从cin读入一组词并把它们存入一vector对象,然后设法把所有词都改写为大写形式
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
vector<string> V;
for (string t; cin >> t; V.push_back(t));
for (auto &str : V)
for (auto &ch : str)
ch = toupper(ch);
for (auto i = V.begin(); i != V.end(); ++i)
cout << *i << endl;
return 0;
}
用法示例
#include <vector>
#include <iostream>
int main( )
{
using namespace std;
vector <int> v1;
vector <int>::iterator v1_Iter;
v1.push_back( 1 );
v1.push_back( 2 );
for ( v1_Iter = v1.begin( ) ; v1_Iter != v1.end( ) ; v1_Iter++ )
cout << *v1_Iter << endl;
}
Output
1
2