一.程序要把一个txt文件按行读入一个vector<string>中,然后每行再细分为单词输出,用了sstream的函数
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <sstream>
#include <stdio.h>
using namespace std;
int main()
{
string word;
string line;
vector<string> t_vStr;
ifstream open_file("F://test.txt");
if ( !open_file ) cout<<"打开失败"<<endl;
while( getline ( open_file, line ) )
t_vStr.push_back(line);
open_file.close();
// cerr<<t_vStr.size();
while ( !t_vStr.empty() )
{
string tmpStr = t_vStr.back();
t_vStr.pop_back();
istringstream stream( tmpStr );
while ( stream >> word )
cout<<word<<endl;
}
return 0;
}