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

C风格字符串有关问题

2012-11-06 
C风格字符串问题#include iostream#include stringusing namespace stdint main(){string strcins

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”

热点排行