题目
- 读取一段文本到vector
- 每个单词存储为vector的一个元素.
- 把vector中每个单词转化为大写字母.
- 输出vector对象中转化后的元素.
- 每八个单词为一行输出
分析
- 第一,二不解释.
- C++里面的toupper(c)和Java里面的toUpperCase()最大的区别是:C++是转换单个字符,而Java的则是转换一个字符串
- 后面的不解释了.
源代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | /************************************************************************* > File Name: test.3.14.cpp > Author: puruidong > Mail: 1@w1520.com > Created Time: 2013年12月22日 星期日 00时52分56秒 ************************************************************************/ #include<iostream> #include<vector> #include<string> using namespace std; using std::string; int main() { vector<string> message; cout << "input message?" << endl; string mess ; while(cin >> mess){ message.push_back(mess); } if(message.size()<7){ cout << " error , >8 character " << endl; return -1; } for(vector<string>::size_type index=0;index!=message.size();++index){ for (vector<string>::size_type toup = 0;toup<message[index].size();++toup){ ((message[index])[toup])=toupper((message[index])[toup]); cout << ((message[index])[toup]); } cout << "\t" ; if(index==7){ cout << "\n" << endl; } } return 0; } |