c语言write_string,writestring("\");有关问题?

当前位置:我的异常网» C语言 » writestring("\");有关问题?

writestring("\");有关问题?

www.myexceptions.net  网友分享于:2015-01-01  浏览:0次

writestring("\");问题???

cstdiofile f;

f.writestring("C:\Documents and Settings\Administrator\桌面\新建文件夹");

里面的“\”  写入有问题 ,请问有什么别的方法可以解决吗?

------解决思路----------------------

将每个\替换为\\

C++ Character Constants

Character constants are one or more members of the “source character set,” the character set in which a program is written, surrounded by single quotation marks ('). They are used to represent characters in the “execution character set,” the character set on the machine where the program executes.

Microsoft Specific

For Microsoft C++, the source and execution character sets are both ASCII.

END Microsoft Specific

There are three kinds of character constants:

Normal character constants

Multicharacter constants

Wide-character constants

Note   Use wide-character constants in place of multicharacter constants to ensure portability.

Character constants are specified as one or more characters enclosed in single quotation marks. For example:

char ch = 'x';          // Specify normal character constant.

int mbch = 'ab';        // Specify system-dependent

//  multicharacter constant.

wchar_t wcch = L'ab';   // Specify wide-character constant.

Note that mbch is of type int. If it were declared as type char, the second byte would not be retained. A multicharacter constant has four meaningful characters; specifying more than four generates an error message.

Syntax

character-constant :

'c-char-sequence'

L'c-char-sequence'

c-char-sequence :

c-char

c-char-sequence c-char

c-char :

any member of the source character set except the single quotation mark ('), backslash (\), or newline character

escape-sequence

escape-sequence :

simple-escape-sequence

octal-escape-sequence

hexadecimal-escape-sequence

simple-escape-sequence : one of

\' \" \? \\

\a \b \f \n \r \t \v

octal-escape-sequence :

\octal-digit

\octal-digit octal-digit

\octal-digit octal-digit octal-digit

hexadecimal-escape-sequence :

\xhexadecimal-digit

hexadecimal-escape-sequence hexadecimal-digit

Microsoft C++ supports normal, multicharacter, and wide-character constants. Use wide-character constants to specify members of the extended execution character set (for example, to support an international application). Normal character constants have type char, multicharacter constants have type int, and wide-character constants have type wchar_t. (The type wchar_t is defined in the standard include files STDDEF.H, STDLIB.H, and STRING.H. The wide-character functions, however, are prototyped only in STDLIB.H.)

The only difference in specification between normal and wide-character constants is that wide-character constants are preceded by the letter L. For example:

char schar = 'x';               // Normal character constant

wchar_t wchar = L'\x81\x19';    // Wide-character constant

Table 1.2 shows reserved or nongraphic characters that are system dependent or not allowed within character constants. These characters should be represented with escape sequences.

Table 1.2   C++ Reserved or Nongraphic Characters

Character ASCII

Representation ASCII

Value Escape Sequence

Newline NL (LF) 10 or 0x0a \n

Horizontal tab HT 9 \t

Vertical tab VT 11 or 0x0b \v

Backspace BS 8 \b

Carriage return CR 13 or 0x0d \r

Formfeed FF 12 or 0x0c \f

Alert BEL 7 \a

Backslash \ 92 or 0x5c \\

Question mark ? 63 or 0x3f \?

Single quotation mark ' 39 or 0x27 \'

Double quotation mark " 34 or 0x22 \"

Octal number ooo — \ooo

Hexadecimal number hhh — \xhhh

Null character NUL 0 \0

If the character following the backslash does not specify a legal escape sequence, the result is implementation defined. In Microsoft C++, the character following the backslash is taken literally, as though the escape were not present, and a level 1 warning (“unrecognized character escape sequence”) is issued.

Octal escape sequences, specified in the form \ooo, consist of a backslash and one, two, or three octal characters. Hexadecimal escape sequences, specified in the form \xhhh, consist of the characters \x followed by a sequence of hexadecimal digits. Unlike octal escape constants, there is no limit on the number of hexadecimal digits in an escape sequence.

Octal escape sequences are terminated by the first character that is not an octal digit, or when three characters are seen. For example:

wchar_t och = L'\076a';  // Sequence terminates at a

char    ch = '\233';     // Sequence terminates after 3 characters

Similarly, hexadecimal escape sequences terminate at the first character that is not a hexadecimal digit. Because hexadecimal digits include the letters a through f (and A through F), make sure the escape sequence terminates at the intended digit.

Because the single quotation mark (') encloses character constants, use the escape sequence \' to represent enclosed single quotation marks. The double quotation mark (") can be represented without an escape sequence. The backslash character (\) is a line-continuation character when placed at the end of a line. If you want a backslash character to appear within a character constant, you must type two backslashes in a row (\\). (SeePhases of Translation in the Preprocessor Reference for more information about line continuation.)

文章评论

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
实现 C 语言的 QR Code 生成并保存为 PNG 文件,可以通过以下步骤: 1. 下载 qrcodegen 库:https://github.com/nayuki/QR-Code-generator 2. 将 qrcodegen.c 和 qrcodegen.h 拷贝到你的项目中。 3. 安装 libpng 库,用于生成 PNG 文件。 4. 编写代码,实现 QR Code 的生成和保存。 下面是一个简单的示例代码: ```c #include <stdio.h> #include <stdlib.h> #include <stdint.h> #include "qrcodegen.h" #include <png.h> // 定义 PNG 文件的宽度和高度 #define PNG_WIDTH 256 #define PNG_HEIGHT 256 // 定义 PNG 文件的颜色类型和位深度 #define PNG_COLOR_TYPE PNG_COLOR_TYPE_GRAY #define PNG_BIT_DEPTH 8 // 保存 QR Code 为 PNG 文件 void save_qr_code(const uint8_t qrcode[qrcodegen_BUFFER_LEN_MAX], int size) { // 创建 PNG 结构体 png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); if (!png_ptr) { fprintf(stderr, "Error: png_create_write_struct()\n"); exit(EXIT_FAILURE); } // 创建 PNG 信息结构体 png_infop info_ptr = png_create_info_struct(png_ptr); if (!info_ptr) { fprintf(stderr, "Error: png_create_info_struct()\n"); png_destroy_write_struct(&png_ptr, NULL); exit(EXIT_FAILURE); } // 设置错误处理 if (setjmp(png_jmpbuf(png_ptr))) { fprintf(stderr, "Error: setjmp()\n"); png_destroy_write_struct(&png_ptr, &info_ptr); exit(EXIT_FAILURE); } // 打开文件 FILE *fp = fopen("qrcode.png", "wb"); if (!fp) { fprintf(stderr, "Error: fopen()\n"); png_destroy_write_struct(&png_ptr, &info_ptr); exit(EXIT_FAILURE); } // 初始化 PNG 文件头 png_init_io(png_ptr, fp); png_set_IHDR(png_ptr, info_ptr, PNG_WIDTH, PNG_HEIGHT, PNG_BIT_DEPTH, PNG_COLOR_TYPE, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); // 写入 PNG 文件头 png_write_info(png_ptr, info_ptr); // 填充 QR Code 数据到 PNG 文件中 for (int y = 0; y < size; y++) { png_bytep row = (png_bytep) malloc(PNG_WIDTH * sizeof(png_byte)); for (int x = 0; x < size; x++) { row[x] = qrcodegen_getModule(qrcode, x, y) ? 0 : 255; } png_write_row(png_ptr, row); free(row); } // 写入 PNG 文件尾 png_write_end(png_ptr, info_ptr); // 关闭文件和销毁 PNG 结构体 fclose(fp); png_destroy_write_struct(&png_ptr, &info_ptr); } int main() { // 生成 QR Code 数据 uint8_t qrcode[qrcodegen_BUFFER_LEN_MAX]; const char *text = "Hello, QR Code!"; enum qrcodegen_Ecc errCorLvl = qrcodegen_Ecc_LOW; uint8_t *qrcodeData = qrcodegen_encodeText(text, qrcode, errCorLvl, qrcodegen_VERSION_MIN, qrcodegen_VERSION_MAX, qrcodegen_Mask_AUTO, true); int qrcodeSize = qrcodegen_getSize(qrcodeData); // 保存 QR Code 为 PNG 文件 save_qr_code(qrcodeData, qrcodeSize); // 释放 QR Code 数据 free(qrcodeData); return 0; } ``` 以上代码会生成一个大小为 256x256 的 PNG 文件,内容为 "Hello, QR Code!" 的 QR Code。如果需要生成不同大小的 QR Code,只需要修改 PNG 的宽度和高度即可。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值