/*相关知识点 :
size_type vector 和许多标准库的类型一样都定义了一些配套类型(companion type),通过这些配套类型,能是标准库类的使用能与机器无关(machine independent)处理容器中的字符串有点类似与操作二维数组中某个元素。
*/
/*modified by quanspace 2013-02-06 18:16*Read some text into a vector, storing each word in the input as an
*element in the vector. transform each word into uppercase letters.
*print eight words to a line.
*/
# include <iostream>
# include <vector>
# include <string>
using namespace std;
int main(){
vector<string> word_vec;
string word;
cout<<"Input some text :"<<endl;
while(cin>>word){
if(word == "esc!!!") break;
word_vec.push_back(word);
}
for(vector<string>::size_type i = 0; i != word_vec.size(); ++i){
for(int j = 0; j != word_vec[i].size(); ++j)
word_vec[i][j] = toupper(word_vec[i][j]);
if(i%8 == 0)
cout<<endl;
cout<<word_vec[i]<<" ";
}
return 0;
}

参考 primer 4 edition excercises 3.14
本文介绍了一个使用C++编程语言处理文本输入的方法,包括读取文本、将单词转换为大写字母以及按特定格式打印输出。该程序利用了标准库中的vector容器来存储输入的每个单词。
2万+

被折叠的 条评论
为什么被折叠?



