注册 登录
编程论坛 C++教室

我也写了一个C++程序 一个C++ Primer第四版里面的习题

zklhp 发布于 2014-01-25 22:01, 470 次点击
Exercise
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 编辑 ]
1 回复
#2
TonyDeng2014-01-26 15:08
學習了!
1