How read/write them into arrays

This is a discussion on How read/write them into arrays within the C++ Programming forums, part of the General Programming Boards category; Hello, all: The following is a part of an initial market data: 20090319,A,14.6,14.93,14.45,14.74,27928 20090320,A,14.75,14.95,14.29,14.43,42467 20090323,A,15,15.89,15,15.89,46303 20090324,A,15.66,16.055,15.63,15.79,27188 20090325,A,16.02,16.43,15.5401,15.96,29293 20090326,A,16.05,17.18,15.81,17.14,59793 20090327,A,16.79,16.96,16.21,16.21,32163 20090330,A,15.82,15.86,15.14,15.39,39704 ...

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    30

    How read/write them into arrays

    Hello, all: The following is a part of an initial market data:

    20090319,A,14.6,14.93,14.45,14.74,27928
    20090320,A,14.75,14.95,14.29,14.43,42467
    20090323,A,15,15.89,15,15.89,46303
    20090324,A,15.66,16.055,15.63,15.79,27188
    20090325,A,16.02,16.43,15.5401,15.96,29293
    20090326,A,16.05,17.18,15.81,17.14,59793
    20090327,A,16.79,16.96,16.21,16.21,32163
    20090330,A,15.82,15.86,15.14,15.39,39704
    20090331,A,15.52,15.7,15.27,15.37,47358
    20090401,A,15.12,16.13,15.02,16,39561
    20090402,A,16.39,16.77,16.18,16.32,42830
    20090403,A,15.7,16.6,15.7,16.46,28789
    20090406,A,16.31,16.32,15.74,15.98,33559
    20090407,A,15.67,15.74,15.39,15.6,35614

    It consists of 7-column, the columns are separated by comma ','.

    Now I want to read/write the 1st, 2nd and 6th columns into different arrays
    data[], Name[] and close[], which C++ language sentence can do this job.

  2. #2
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,403
    if you know c++ use a class or a structure eg 'marketdata' with attributes, data, name, and close

    then declare an array of objects of this class

    marketdata records[10];

    then you can put it in a loop and read the info into the structure like records[i].close =....

  3. #3
    Registered User
    Join Date
    Sep 2005
    Posts
    30
    Quote Originally Posted by rogster001 View Post
    if you know c++ use a class or a structure eg 'marketdata' with attributes, data, name, and close

    then declare an array of objects of this class

    marketdata records[10];

    then you can put it in a loop and read the info into the structure like records[i].close =....
    Code:
    The initial file is marketdate.txt, 1st column is date, 2nd Name, 3-6 columnsare prices. My purpose is to read date, name and 6th's price into array date[365], name[ ] and close[365].
    
    I guess the meaning of your answer may like:
    
    class  marketdata
    {
       public:
                 string   date;
                 string   name;
                 float     close;
    };
    
    int  main( )
     {
         marketdata data_array[ 7][365];
      (to read marketdate.txt, how?)..
               
     }
    
    Now the question is how to read the related data in the marketdat.txt
    into the array?

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    What's wrong with >>?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. pointers & arrays and realloc!
    By zesty in forum C Programming
    Replies: 14
    Last Post: 01-19-2008, 03:24 PM
  2. Replies: 16
    Last Post: 01-01-2008, 03:07 PM
  3. Need Help With 3 Parallel Arrays Selction Sort
    By slickwilly440 in forum C++ Programming
    Replies: 4
    Last Post: 11-19-2005, 09:47 PM
  4. Replies: 4
    Last Post: 01-30-2005, 03:50 AM
  5. Crazy memory problem with arrays
    By fusikon in forum C++ Programming
    Replies: 9
    Last Post: 01-15-2003, 08:24 PM

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