【C++ Primer 5th】3.3.3_3.17作业

#include <iostream>
#include <vector>
#include <string>
#include <cctype>


using std::vector;
using std::string;
using std::cin;
using std::cout;
using std::endl;


void WordToUpper(string& word)
{
for(string::size_type idx = 0; idx < word.size(); idx++)
{
if(islower(word[idx]))
{
word[idx] = toupper(word[idx]);
}
}
}


void TextToUpper(vector<string>& text)
{
for(vector<string>::size_type idx = 0; idx < text.size(); idx++)
{
WordToUpper(text[idx]);
}
}


void GetText(vector<string>& text)
{
string word;
while(cin >> word)
{
text.push_back(word);
}
}


void OutputText(vector<string>& text)
{
for(vector<string>::size_type idx = 0; idx < text.size(); idx++)
{
cout << text[idx] << endl;
}
}


int main()
{
cout << "plz input a text to upper" << endl;
vector<string> text;
GetText(text);
TextToUpper(text);
OutputText(text);
return 0;
}

猜你喜欢

转载自blog.csdn.net/zamely/article/details/79990284