Debug Error!解决方法
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++ codeword2[5] = '\0'; // 越界啦