Class Array Problems :(

This is a discussion on Class Array Problems :( within the C++ Programming forums, part of the General Programming Boards category; Hey All, I'm having a little bit of trouble figuring out how to do this and any help would really ...

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,687
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,687
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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, 10: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21