练习2-6:修改Fillvector.cpp使它能把vector中的所有元素连接成单独的一个字符串,并打印,但不要加上行号。

    技术2022-05-19  26

    #include <string>#include <iostream>#include <fstream>#include <vector>using namespace std;

    void main(){ vector<string> v; ifstream in("main.cpp"); string str, word, temp; while (in >> word)  v.push_back(word);

     for (int i = 0; i < v.size(); i++) {   temp = v[i] + " ";  str += temp; }

     cout << str << endl;}


    最新回复(0)