vector常用的输出方式

    技术2022-05-11  3

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

    using namespace std;int main(){     string word;     vector<string> vec1;    // empty vector

         while (cin >> word)  {         vec1.push_back(word);     // append word to text

    /*一种*/    copy(vec1.begin(),vec1.end(),ostream_iterator<string>(cout," "));   cout<<endl;

    /*二种*/

         vector<string>::iterator it;    for (it=vec1.begin();it!=vec1.end();it++)       cout<<*it<<" ";      }

      return 0;}


    最新回复(0)