新手求助各位大大,一个关于while的问题

camelisi 2008-10-16 10:02:50
我想从输入流读入若干个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;
}



...全文
42 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
camelisi 2008-10-16
  • 打赏
  • 举报
回复
十分谢谢
taodm 2008-10-16
  • 打赏
  • 举报
回复
回车-ctrl_z-回车

64,654

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧