我正在制作莫尔斯码转换器,它完成了,我解决了这个问题,但我不明白它。 picture represents the problem一个奇怪的字符出现在我的字符数组中的第一个字符
这是一些代码:
string txt,result;
int x;
cout << "Enter the text you want to convert\n";
getline (cin,txt);
x = txt.size();
char text[x];
strcat(text,txt.c_str());
cout<<"txt = "<<txt<<"\n"<<"text = "<<text<<endl;
我只是想知道那是什么char
,为什么它会出现。
发布可以发布为图片的内容不好。 – MikeCAT
坏字符是随机的,后面跟纯运气的'\ 0'。使用'strcpy',而不是'strcat'。 'x'应该是'txt.size()+ 1'(对于结尾''\ 0'') – manuell