Thread: Any good way of processing file data?

  1. #1
    Registered User
    Join Date
    Jun 2010
    Posts
    5

    Any good way of processing file data?

    If there's file which contains strings in the following format

    Howard SaleAssociate 7-Eleven IBM .....(can be continued)
    Jack Manager Microsoft IBM Dell Lenovo....
    ...
    and i have
    Code:
    class interviewee
    {
    name
    position
    list<string> experience
    so on

    The first and second token in each line are useful, but the rest of the line is the same type and I want to store them separately. (The first two token in each line are variables, then the rest of the line store in list)

    If I use getline(char,100,' '), what's the best way of storing them ?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,412
    Quote Originally Posted by samsun387
    If I use getline(char,100,' '), what's the best way of storing them ?
    Don't use that

    One approach is to use the version of std::getline for std::string. So you read line by line. For each line, you use the string to initialise a stringstream, then you read the tokens as "words" from the stringstream into string objects. Presumably you would handle the first and second tokens separately, then read the rest in a loop into the list.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Jun 2010
    Posts
    5
    istream& getline (char* s, streamsize n );
    istream& getline (char* s, streamsize n, char delim );

    char s[200]; so when I read line by line, then the whole line is stored in this array of char. s[0] will be 'H' in my example.
    Is this easier though?

    Thank you Laserlight

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. xor linked list
    By adramalech in forum C Programming
    Replies: 23
    Last Post: 10-14-2008, 10:13 AM
  2. Bitmasking Problem
    By mike_g in forum C++ Programming
    Replies: 13
    Last Post: 11-08-2007, 12:24 AM
  3. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  4. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 06:51 PM
  5. what does this mean to you?
    By pkananen in forum C++ Programming
    Replies: 8
    Last Post: 02-04-2002, 03:58 PM