www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/07/04/02:26:14

Date: Fri, 4 Jul 1997 02:25:39 -0400 (EDT)
From: Timothy Robb <trobb AT neutrino DOT phys DOT laurentian DOT ca>
To: djgpp AT delorie DOT com
Subject: vector<string> problem
Message-ID: <Pine.SGI.3.91.970704022207.5903A-100000@neutrino.phys.laurentian.ca>
MIME-Version: 1.0

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019