请看这个代码错在哪里?(此代码是C++ Primer 3ed 第6章的源代码)
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
#include <iostream>
#include <fstream>
#include <stddef>
extern vector<string,allocator> *retrieve_text();
int main()
{
vector<string,allocator> *text_file = retrieve_text();
cout << "----------- about to generate text read --------------\n";
ostream_iterator< string > output( cout, "\n" );
copy( text_file->begin(), text_file->end(), output );
return 0;
}
vector<string,allocator>*
retrieve_text()
{
string file_name;
cout << "please enter file name: ";
cin >> file_name;
ifstream infile( file_name.c_str(), ios::in );
if ( !infile ) {
cerr << "oops! unable to open file "
<< file_name << " -- bailing out!\n";
exit( -1 );
}
else cout << "\n";
vector<string,allocator> *lines_of_text = new vector<string,allocator>;
string textline;
typedef pair<string::size_type, int> stats;
stats maxline;
int linenum = 0;
while ( getline( infile, textline, '\n' ))
{
cout << "line read: " << textline << "\n";
if ( maxline.first < textline.length() )
{
maxline.first = textline.length();
maxline.second = linenum;
}
lines_of_text->push_back( textline );
linenum++;
}
cout << "\n";
cout << "number of lines: "
<< lines_of_text->size() << "\n";
cout << "maximum length: "
<< maxline.first << "\n";
cout << "longest line: "
<< (*lines_of_text)[ maxline.second ] << "\n";
return lines_of_text;
}
此代码是C++ Primer 3ed 第6章的源代码,得自侯先生的主页
据侯先生说,在他的win + VC6 上可以顺利通过编译
可惜偶的win2000+ vc6 上无法编译,请各位指点!