GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 10-Nov-2003, 12:27
nattylife nattylife is offline
New Member
 
Join Date: Nov 2003
Location: SO FLA
Posts: 1
nattylife is an unknown quantity at this point

vector prob


hey guys im new here, ive got a prog prob and need to know what im missing here:

ive got a vector of type struct, and i want to read in from a file.
so lets say
CPP / C++ / C Code:
struct entry
{ string key;
   string value;
};

vector<entry> DB;

and i want to read from a file that has only 2 words per index of the vector ie.
input file=

animal cat
plant rose
car ford
etc...

im gonna put it in a while loop but i cant figure out how to use the push_back function to fill the vector with the input... is it something like this?
CPP / C++ / C Code:
ifstream d_file;
      d_file.open("input.txt");
      while(!d_file.eof())
	  {
		  d_file>>d_file[index].key.pushback();  // this wont work
		  d_file>>d_file[index].value.pushback();
                   }

where index is some int used to hold the size of the vector. do i need to use another method to fill this vector?
thanx a bunch!
  #2  
Old 15-Nov-2003, 08:41
akupers akupers is offline
New Member
 
Join Date: Nov 2003
Posts: 2
akupers is an unknown quantity at this point
Code seems ok but try push_back() instead of pushback()
and I suggest not to use 'struct' but 'class' (but that's not really important here)
 
 

Recent GIDBlogPython ebook by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 17:45.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.