Chinaunix首页 | 论坛 | 博客
  • 博客访问: 157370
  • 博文数量: 76
  • 博客积分: 1513
  • 博客等级: 上尉
  • 技术积分: 755
  • 用 户 组: 普通用户
  • 注册时间: 2011-11-25 15:15
文章分类

全部博文(76)

文章存档

2012年(2)

2011年(74)

我的朋友

分类: C/C++

2011-11-27 14:23:12

  1. #include<iostream>
  2. #include<vector>
  3. using namespace std;
  4. #define VEC_STR vector<string>//宏定义
  5. int main()
  6. {
  7.       VEC_STR ivec;
  8.       string word;
  9.       cout<<"input the element:(input OK to stop input)"<<endl;
  10.       do
  11.       {
  12.              cin>>word;
  13.              if(word=="OK")
  14.                     break;
  15.              ivec.push_back(word);
  16.       }while(true);
  17.       VEC_STR::iterator iter=ivec.begin();
  18.       do
  19.       {
  20.              if(iter==ivec.end())//指向ivec末端元素的下一个
  21.                     break;
  22.              cout<<*iter<<" ";
  23.              ++iter;
  24.       }
  25.       while(true);
  26.       cout<<endl;
  27.       system("pause");
  28.       return 0;
  29. }

/*

input the element:(input OK to stop input)

chinese

academy

of

sciences

OK

chinese academy of sciences

请按任意键继续. . .

*/

阅读(659) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~