C风格字符串问题
#include <iostream>
#include <string>
using namespace std;
int main()
{
string str;
cin>>str;
char *text=new char[str.size()+1];
strcpy(text,str.c_str());
text[strlen(text)+1]='\0';
strcat(text,'\0');//不用上句用此句却运行时出错,为什么
system("pause");
return 0;
}
[解决办法]
char *strcat( char *strDestination, const char *strSource );
要2个串。
strcat(text,'\0');// “\n”