#练习8.4:编写函数,以读模式打开一个文件,将其内容读入到一个string的vector种,将每一行作为一个独立的元素存于vector中.
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
int main(int argc,char **argv)
{
std::ifstream input(argv[1] );
std::vector<std::string> vs;
std::string str;
while(getline(input,str))
{
vs.push_back(str);
}
for(const auto &vc:vs)
{
std::cout<<vc<<std::endl;
}
}#运行结果:
本文出自 “奔跑的驴” 博客,请务必保留此出处http://amgodchan.blog.51cto.com/9521586/1581027
原文地址:http://amgodchan.blog.51cto.com/9521586/1581027