#include<iostream>
#include<string>
#include<vector>
#include<cctype>
using namespace std;
int main(){
vector<string> svec;
string str;
cout<<"Enter text ctrl(z to end):"<<endl;
while(cin>>str)
svec.push_back(str);
if(svec.size()==0){
cout<<"no string"<<endl;
return -1;}
cout<<"transform element 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)
cout<<endl;
}
return 0;
}
在for语句之前可以运行,后面就不行了,什么地方出问题了?
改为
if((ix+1)%8==0)
之后,
可以运行,但是不输出结果?????????????
CNnumen911所说的去掉while之后是可以运行,
但题目是:要求读入一段文本到vector对象,每个单词存储为vector中的一个元素。要求把每个单词换成大写字母,每8个单词为一行。
(去掉while后读入的只是一个对象,而vecort可以定义对象的集合)
信息学奥赛 1138-将字符串中的小写字母转换成大写字母