#include <stdio.h>
int main() {
printf("c:\\test\\add\\72_12\\test.c");
return 0;
}
c: estdd:_12 est.c
| 序列 | 轉義為 | 原字串位置 |
|---|---|---|
\t | Tab (水平定位) | \test 中的 \t |
\a | 響鈴 (BEL) | \add 中的 \a |
\7 | 八進位 \7 = BEL | \72_12 中的 \7 |
其餘字元正常輸出,導致路徑變得面目全非。
"c:\\test\\add\\72_12\\test.c""c:/test/add/72_12/test.c"R"(...)",C 語言無此特性)。#include <stdio.h>
#include <string.h>
int main() {
// 實際記憶體中儲存的字元:c : \ t e s t \ a d d \ a _ 1 2 \ t e s t . c
// 每個轉義序列佔 1 位元組
printf("%zu\n", strlen("c:\\test\\add\\72_12\\test.c"));
return 0;
}
19
c : \ t e s t \ a d d \ 7 2 _ 1 2 \ t e s t . c
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
字串常數中,反斜槓啟動轉義;若要表達反斜槓本身,必須寫雙反斜槓 \\\\。