关于vc编译问题?
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
#include <iostream.h>
#include <fstream.h>
#include <stddef.h>
using namespace std;
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;
}
/*
dumbo[107] ~/d.stdlib => a.out
please enter file name: alice_emma
line read: Alice Emma has long flowing red hair. Her Daddy says
line read: when the wind blows through her hair, it looks almost alive,
line read: like a fiery bird in flight. A beautiful fiery bird, he tells her,
line read: magical but untamed. "Daddy, shush, there is no such thing,"
line read: she tells him, at the same time wanting him to tell her more.
line read: Shyly, she asks, "I mean, Daddy, is there?"
number of lines: 6
maximum length: 66
longest line: like a fiery bird in flight. A beautiful fiery bird, he tells her,
----------- about to generate text read --------------
Alice Emma has long flowing red hair. Her Daddy says
when the wind blows through her hair, it looks almost alive,
like a fiery bird in flight. A beautiful fiery bird, he tells her,
magical but untamed. "Daddy, shush, there is no such thing,"
she tells him, at the same time wanting him to tell her more.
Shyly, she asks, "I mean, Daddy, is there?"
*/
//出现的问题
Compiling...
main0.cpp
C:\exam\main0\main0.cpp(13) : error C2955: 'allocator' : use of class template requires template argument list
c:\program files\microsoft visual studio\vc98\include\xmemory(72) : see declaration of 'allocator'
C:\exam\main0\main0.cpp(17) : error C2955: 'allocator' : use of class template requires template argument list
c:\program files\microsoft visual studio\vc98\include\xmemory(72) : see declaration of 'allocator'
C:\exam\main0\main0.cpp(21) : error C2664: '__thiscall std::ostream_iterator,class std::allocator >,char,struct std::char_traits >::std::ostream_iterator,class std::allocator >,char,struct std::char_traits >(class std::basic_ostream > &,const char *)' : cannot convert parameter 1 from 'class ostream_withassign' to 'class std::basic_ostream > &'
A reference that is not to 'const' cannot be bound to a non-lvalue
C:\exam\main0\main0.cpp(22) : error C2663: 'begin' : 2 overloads have no legal conversion for 'this' pointer
C:\exam\main0\main0.cpp(22) : error C2663: 'end' : 2 overloads have no legal conversion for 'this' pointer
C:\exam\main0\main0.cpp(27) : error C2955: 'allocator' : use of class template requires template argument list
c:\program files\microsoft visual studio\vc98\include\xmemory(72) : see declaration of 'allocator'
C:\exam\main0\main0.cpp(33) : error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'class std::basic_string,class std::allocator >' (or there is no acceptable conversion)
C:\exam\main0\main0.cpp(35) : error C2872: 'ifstream' : ambiguous symbol
C:\exam\main0\main0.cpp(38) : error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class std::basic_string,class std::allocator >' (or there is no acceptable conversion)
C:\exam\main0\main0.cpp(43) : error C2955: 'allocator' : use of class template requires template argument list
c:\program files\microsoft visual studio\vc98\include\xmemory(72) : see declaration of 'allocator'
C:\exam\main0\main0.cpp(43) : error C2955: 'allocator' : use of class template requires template argument list
c:\program files\microsoft visual studio\vc98\include\xmemory(72) : see declaration of 'allocator'
C:\exam\main0\main0.cpp(43) : error C2512: 'vector,class std::allocator >,class std::allocator>' : no appropriate default constructor available
C:\exam\main0\main0.cpp(50) : error C2784: 'class std::basic_istream<_E,_Tr> &__cdecl std::getline(class std::basic_istream<_E,_Tr> &,class std::basic_string<_E,_Tr,_A> &,const _E)' : could not deduce template argument for 'class std::basic_istream<_E,_Tr> &' from 'class ifstream'
C:\exam\main0\main0.cpp(50) : error C2784: 'class std::basic_istream<_E,_Tr> &__cdecl std::getline(class std::basic_istream<_E,_Tr> &,class std::basic_string<_E,_Tr,_A> &,const _E)' : could not deduce template argument for 'class std::basic_istream<_E,_Tr> &' from 'class ifstream'
C:\exam\main0\main0.cpp(50) : error C2784: 'class std::basic_istream<_E,_Tr> &__cdecl std::getline(class std::basic_istream<_E,_Tr> &,class std::basic_string<_E,_Tr,_A> &,const _E)' : could not deduce template argument for 'class std::basic_istream<_E,_Tr> &' from 'class ifstream'
C:\exam\main0\main0.cpp(50) : error C2780: 'class std::basic_istream<_E,_Tr> &__cdecl std::getline(class std::basic_istream<_E,_Tr> &,class std::basic_string<_E,_Tr,_A> &)' : expects 2 arguments - 3 provided
c:\program files\microsoft visual studio\vc98\include\string(145) : see declaration of 'getline'
C:\exam\main0\main0.cpp(50) : fatal error C1903: unable to recover from previous error(s); stopping compilation
Error executing cl.exe.
这是c++ primer 的源码,由于本人还未学vc,希望各位高手能写个步骤给小弟编译成功!还有alice_emma这个文件是要自己建立的吗?谢谢!