有关 c++ 的问题
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <iterator>
#include <algorithm>
using namespace std;
string read_file_into_string()
{
ifstream ifile( "test1.txt" );
if( !ifile )
cout << "error\n";
ostringstream buf;
char ch;
while ( buf && ifile.get( ch ) )
buf.put( ch );
return buf.str();
}
int main()
{
string text = read_file_into_string();
cout << text;
vector<string::size_type> lines_of_text;
string::size_type pos = 0;
while( pos != string::npos )
{
pos = text.find( '\n', pos );
lines_of_text.push_back( pos );
} //调试时这里变成了死循环,跳不出来;高手指点
ostream_iterator<string::size_type> out( cout , " " );
copy( lines_of_text.begin(), lines_of_text.end(), out );
cin.get();
}