新手求助各位大大,一个关于while的问题
我想从输入流读入若干个string,将其保存在vector中,并将每个string 转化成大写字母输出,但是输入了几个string回车后,没有任何反应,哪个高人帮我下,小弟不胜感激.
程序是这样的:
#include<iostream>
#include<string>
#include<vector>
#include<cctype>
using namespace std;
int main()
{
vector<string> svec;
string str;
//读入文本到vector对象
cout<<"Enter text(Ctrl+Z to end):"<<endl;
while(cin>>str)
svec.push_back(str);
//将vector对象中每个单词转换成大写字母
if(svec.size() == 0)
{
cout<<"No string ?!"<<endl;
return -1;
}
cout<<"Transformed elements from the vector:"<<endl;
for(vector<string>::size_type ix = 0; ix != svec.size(); ++ix)
{
for(string::size_type index = 0; index != svec[ix].size(); ++index)
if(islower(svec[ix][index]))
svec[ix][index] = toupper(svec[ix][index]);
cout<<svec[ix]<<" ";
if((ix+1) % 8 == 0)
cout<<endl;
}
return 0;
}
程序是这样的:
#include<iostream>
#include<string>
#include<vector>
#include<cctype>
using namespace std;
int main()
{
vector<string> svec;
string str;
//读入文本到vector对象
cout<<"Enter text(Ctrl+Z to end):"<<endl;
while(cin>>str)
svec.push_back(str);
//将vector对象中每个单词转换成大写字母
if(svec.size() == 0)
{
cout<<"No string ?!"<<endl;
return -1;
}
cout<<"Transformed elements from the vector:"<<endl;
for(vector<string>::size_type ix = 0; ix != svec.size(); ++ix)
{
for(string::size_type index = 0; index != svec[ix].size(); ++index)
if(islower(svec[ix][index]))
svec[ix][index] = toupper(svec[ix][index]);
cout<<svec[ix]<<" ";
if((ix+1) % 8 == 0)
cout<<endl;
}
return 0;
}
...全文


