【发布时间】:2014-03-02 10:55:28
【问题描述】:
我有一个问题,不要编译这段代码,而是执行这个程序。当我在终端中运行它时,它会打印前 2 个cout,然后程序停止工作并且窗口上的屏幕告诉你,我认为问题出在strcat。
我正在使用 DEVC++,并且我有 Windows 7 pro。
#include <iostream>
#include <string>
#include <cstdlib>
#include <string.h>
using namespace std;
int main() {
char* cambia[] = {"ciao "};
char* c[] = {"mondo"};
cout << "*c: " << *c << endl;
cout << "*cambia: " << *cambia << endl;
strcat( *cambia, *c );
cout << "*cambia: " << *cambia << endl;
}
【问题讨论】:
-
你看过
strcat的文档吗? -
不要使用 devc++ ,它很古老。
-
您没有为
strcat()的结果保留足够的空间,*cambia也是错误的。试试……比如char cambia[100] = "ciao ";和strcat( cambia, *c );。 -
在此处查看
strcat的实际操作(对于 C 编程语言):en.cppreference.com/w/c/string/byte/strcat -
你会推荐我什么ide?span>