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

新手此段字符串异常原因

2013-03-22 
新手求助:此段字符串错误原因为什么将输入的字符串连接,并用空格隔开debug错误?#includeiostream#includ

新手求助:此段字符串错误原因
为什么将输入的字符串连接,并用空格隔开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;
}

热点排行