vector中的.begin()和.end()

从cin读入一组词并把它们存入一vector对象,然后设法把所有词都改写为大写形式

#include 
#include 
#include 
using namespace std;

int main() {

	vector<string> V;

	for (string t; cin >> t; V.push_back(t));            //这种循环语句确实简洁

	for (auto &str : V)                                  //范围for语句
		for (auto &ch : str)
			ch = toupper(ch);

	for (auto i = V.begin(); i != V.end(); ++i)
		cout << *i << endl;

	return 0;
}

用法示例

#include 
#include 
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

你可能感兴趣的:(C++,c++)