1
當我嘗試在字符串中添加非ASCII字符時,g ++(v 4.7.3)發出警告。輸出是完全意想不到的。 '23 00 25 30`;無法在字符串中嵌入非ASCII字符
#include <stdio.h>
int main(int argc, char *argv[]) {
char *p = "\x03123";
printf("%02x %02x %02x %02x\n", p[0], p[1], p[2], p[3]);
return 0;
}
我有錯誤
g++ -std=c++11 te2a.cc
te2a.cc: In function ‘int main(int, char**)’:
te2a.cc:5:12: warning: hex escape sequence out of range [enabled by default]
te2a.cc:5:12: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
八進制轉義限制爲1-3位;十六進制轉義對數字位數沒有上限,所以您必須確保末尾有一個非十六進制字符。請注意,輸出中的25和30是完全沒有指定的,因爲您正在訪問超過'p'指向的(2個字符)字符串的末尾。 –