Thread: Class Array Problems :(

  1. #1
    Registered User
    Join Date
    Dec 2006
    Posts
    2

    Class Array Problems :(

    Hey All,
    I'm having a little bit of trouble figuring out how to do this and any help would really be appreciated.
    I'm trying to read from a text file with several entries in the following format.

    "x3","two","Mr. Jones","210"
    ...
    string, string, string, int

    To make it more difficult I am trying to save these values into a class array, where each value is stored in a different array.
    Trying to do this within a function in the implementation file and wondering how to reference in the header.

    Thanks for any insight and help!

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Are commas inside text strings a problem to overcome, like
    "hello, world","another field"
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Dec 2006
    Posts
    2
    Some commas are inside and others are outside.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    So basically, build a small state machine along the lines of
    state = out;

    while ( state == out && ch != '\"' ) advance;
    if ( ch == '\"' ) state = in; advance;
    while ( state == in && ch != '\"' ) copyCharToResult; advance;
    etc etc

    Once you've got to the 2nd " of a pair, then copy the result to wherever you need it to go.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. pointer of array of class
    By 11moshiko11 in forum C++ Programming
    Replies: 5
    Last Post: 04-05-2008, 09:58 AM
  2. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  3. An Array of Classes in a different Class
    By mas0nite in forum C++ Programming
    Replies: 4
    Last Post: 10-05-2006, 02:28 PM
  4. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM
  5. Problems w.r.t Virtual Base Class (inheritance)
    By pankajdynamic in forum C++ Programming
    Replies: 1
    Last Post: 04-15-2002, 10:28 AM