![]() |
#2
TonyDeng2014-01-26 15:08
|
Exercise
3.14:
读入一段文本到 vector 对象,每个单词存储为 vector中的一个元素。把 vector 对象中每个单词转化为大写字母。输出 vector 对象中转化后的元素,每八个单词为一行输出。
3.14:
读入一段文本到 vector 对象,每个单词存储为 vector中的一个元素。把 vector 对象中每个单词转化为大写字母。输出 vector 对象中转化后的元素,每八个单词为一行输出。

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using std::cout;
using std::cin;
using std::endl;
using std::vector;
using std::string;
int main(void)
{
string word;
vector<string> text;
while (cin >> word)
text.push_back(word);
for (vector<string>::size_type i = 0; i != text.size(); i++)
{
transform(text[i].begin(), text[i].end(), text[i].begin(), ::toupper);
cout << text[i] << " ";
if (0 == (i+1) % 8)
cout << endl;
}
return 0;
}
书看了五分之一了 嗯 应该能在年前看完 至于效果就不好说了 欢迎批评指正
[ 本帖最后由 zklhp 于 2014-1-25 22:05 编辑 ]