c_cpp 编写一段程序,用CIN读入一组字符串并把它们存入一个矢量对象。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp 编写一段程序,用CIN读入一组字符串并把它们存入一个矢量对象。相关的知识,希望对你有一定的参考价值。

#include <iostream.h>
#include <string>
#include <vector>
using namespace std;
int main()
{
    vector<string> vString;
    string s;
    char cont = 'y';
    while(cin>>s)
    {
        vString.push_back(s);
        cout << "您要继续吗(y or n)?" <<endl;
        cin >> cont;
        if(cont !='y' && cont != 'Y')break;
    }
    vector<string>::iterator i;
    for(i=vString.begin(); i != vString.end(); i++){
    	cout << *i << endl;
    }
    return 0;
}

以上是关于c_cpp 编写一段程序,用CIN读入一组字符串并把它们存入一个矢量对象。的主要内容,如果未能解决你的问题,请参考以下文章