首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

Debug Error!解决方法

2012-02-17 
Debug Error!!!C/C++ code#include iostream#include cstringusing namespace stdint main(){char wo

Debug Error!!!

C/C++ code
#include <iostream>#include <cstring>using namespace std;int main(){    char word1[] = "abcde";    char word2[5];    strncpy(word2, word1, 4);    word2[5] = '\0';    cout << word2;}


[解决办法]
没有完整安装开发包吧
我编译运行都正常
[root@localhost src]# g++ simple.cpp
simple.cpp:12:2: 警告:文件未以空白行结束
[root@localhost src]# ./a.out
abcd_trV
[解决办法]
C 字符串以 '\0' 结尾

数组下标从 0 开始

C/C++ code
word2[5] = '\0'; // 越界啦 

热点排行
Bad Request.