您的位置:首页 > 编程语言 > C语言/C++

[Thinking in C++]CH02:Ex06 解答

2008-03-09 16:54 344 查看
Problem:Change Fillvector.cpp so that it concatenates all the elements in the vector into a single string before printing it out, but don’t try to add line numbering.

问题:修改Fillvector.cpp,使其在打印出vector内全部元素前,将其全部元素合并为一个字串,但是不需要给每行编号。

//: C02:Fillvector.cpp
// Copy an entire file into a vector of string
#include<string>
#include<iostream>
#include<fstream>
#include<vector>
using namespace std;
void main(){
vector<string>v;
vector<string>u;
ifstream in("2.txt");
string line;
string s;
while(getline(in,line))
v.push_back(line); // Add the line to the end
for(int i=0;i<v.size();i++)
s+=v[i];
cout<<s<<endl;
} ///:~
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: