c**********e 发帖数: 2007 | 1 【 以下文字转载自 Programming 讨论区 】
发信人: careerchange (Stupid), 信区: Programming
标 题: Weird! string length problem.
发信站: BBS 未名空间站 (Sat May 3 21:12:23 2008)
I defined a dynamic array as
char* str= new char[60];
cout << strlen(str) << endl;
The string length is defined to be 60, but the output strlen is 68?
If I use char[10], then the output length is 15?
What is wrong? | n********b 发帖数: 2 | 2 Are you sure you put '\0' at the end? | j*******2 发帖数: 18 | 3 If you use sizeof, the result may be different. |
|