Mail Archives: djgpp/1997/07/04/02:26:14
The following vector<string> test program of mine is giving me some
problems. Mainly it won't compile and give me about 50k of
errors/warnings. It's suppossed to read in a text file to a
vector<string> and then latter display it, which it sadly does under VC++
5.0
How do I get it to work under g++? I'm using g++ 2.7.2.2 with SGI's
latest STL headers under Linux.
Timothy Robb
#include <iostream.h>
#include <fstream.h>
#include <string>
#include <vector.h>
#include <assert.h>
using namespace std;
int main(int argc,char *argv[])
{
if( argc < 2 )
{
cerr << "Requires a file to read in. " << endl;
exit(75);
}
ifstream infile(argv[1]);
assert(infile);
string instring;
vector<string> invec;
while( !infile.eof() )
{
getline(infile, instring);
invec.push_back(instring);
}
vector<string>::iterator it;
for( it = invec.begin(); it != invec.end(); it++)
cout << *it << endl;
return 0;
}
- Raw text -