[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;
} ///:~
问题:修改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;
} ///:~
相关文章推荐
- Thinking in c++ 2nd 习题解答之STL实现(一)
- [Thinking in C++]C02:Ex04 解答及疑惑
- [Thinking in C++]C02:Ex05 解答及心得
- [Thinking in C++]CH02:Ex07 疑惑
- Thinking in C++ 第十三章 动态对象创建
- thinking in C++ 读书日志(七)
- Thinking in C++ 阅读
- 【ThinkingInC++】75、多重继承
- 《thinking in c++》Volume 1知识点总结(一)
- Thinking in C++ ---- Memory Allocation
- Thinking in C++之1.继承与组合概念、区别及优缺点
- Thinking in C++ 读书笔记 之抽象数据类型
- [THINKING IN C++]CHAPTER 04:EXERCISE 04
- Thinking in C++ ----第三章 C++中的C
- 【ThinkingInC++】3、文件的拷贝
- thinking in c++ 卷2
- Thinking in C++ 学习笔记(2)
- 【ThinkingInC++】6、内存存放地址的地方
- 《Thinking in C++》练习题答案——2-3
- 【ThinkingInC++】67、多态性和虚函数