C++ Extracting data from text files

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jan 2008
Posts: 401
Reputation: CoolGamer48 is on a distinguished road 
Solved Threads: 40
CoolGamer48's Avatar
CoolGamer48 CoolGamer48 is offline Offline
Posting Pro in Training

Re: C++ Extracting data from text files

 
0
  #21
Aug 5th, 2008
A vector is a dynamic array. You can use the push_back() method to add an element to the end of the vector, and you can use the overloaded [] operator to access elements. That's just a quick overview though, see the link for more detailed information.

Also, I regret making that comment a few posts above. I think it would be much easier to put the member data into two separate files, one for full and one for young. I hadn't thought of that when I made the post.
I'm a student. If my statements seem too absolute, feel free to coat them with "In my opinion..." or "I believe...".
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 11
Reputation: davidleeis14 is an unknown quantity at this point 
Solved Threads: 0
davidleeis14 davidleeis14 is offline Offline
Newbie Poster

Re: C++ Extracting data from text files

 
0
  #22
Aug 5th, 2008
One thing I do not understand is what is an element, is it the whole line from the txt file or is just a piece of data from it, say the accNum? I just cannot seem to be able to grasp who vectors work, and the link seems to confuse me further, as all of the varibles are integers as my I have a c few types of varibles in my program.

My task asks me to use STL vector of pointers to Members (customers) to represent the scheme
Last edited by davidleeis14; Aug 5th, 2008 at 11:35 am.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 445
Reputation: Agni is a jewel in the rough Agni is a jewel in the rough Agni is a jewel in the rough 
Solved Threads: 69
Sponsor
Agni's Avatar
Agni Agni is offline Offline
Posting Pro in Training

Re: C++ Extracting data from text files

 
0
  #23
Aug 6th, 2008
vector as coolgamer mentioned above is a dynamic array. you can use it to store data.It can grow as per requirement and you dont need to worry about the size at compile time. it's best suited for conditions where you need random search and less of inserts and updates.

example:

  1. vector<int> v;
  2. int i =10;
  3. v.push_back(i);
  4. //fetch an element
  5. cout << v[0] << endl;

when i declare a vector i mention the type of elements it will store, in this case 'int'. then i can insert as many 'int's' into it as needed. if your task requires you to use a vector of Member Pointers then you should declare something like

  1. vector<Member*> v;

and then get pointers to member objects and insert into it.
each value stored in a vector is an element of the vector. its upto you to decide what will be the element in your program.
thanks
-chandra
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 11
Reputation: davidleeis14 is an unknown quantity at this point 
Solved Threads: 0
davidleeis14 davidleeis14 is offline Offline
Newbie Poster

Re: C++ Extracting data from text files

 
0
  #24
Aug 7th, 2008
But if there are different varible types then how do I store them in the same vector and how do I get each piece of data on a line of my text file to be stored in a vector, my text file goes (name, balance, expiry date)?
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 445
Reputation: Agni is a jewel in the rough Agni is a jewel in the rough Agni is a jewel in the rough 
Solved Threads: 69
Sponsor
Agni's Avatar
Agni Agni is offline Offline
Posting Pro in Training

Re: C++ Extracting data from text files

 
0
  #25
Aug 8th, 2008
Then you need to create a structure and create a vector of that structure. which brings us back to the few first replies in this thread and the circle is complete....
thanks
-chandra
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC