新手求助:此段字符串错误原因
为什么将输入的字符串连接,并用空格隔开debug错误?
#include<iostream>
#include<string>
using std::string;
int main()
{
string result,str;
std::cout<<"Enter string(Ctl+Z to end):"<<std::endl;
while(std::cin>>str)
result=result+''+str;----这里有什么问题?
std::cout<<"String equal to the concatenation of these string is:"<<std::endl<<result<<std::endl;
return 0;
}
[解决办法]
是空字符串,不是字符
改为:
#include<iostream>
#include<string>
using std::string;
int main()
{
string result,str;
std::cout<<"Enter string(Ctl+Z to end):"<<std::endl;
while(std::cin>>str)
result=result+" "+str;//----这里有什么问题?
std::cout<<"String equal to the concatenation of these string is:"<<std::endl<<result<<std::endl;
return 0;
}