-3

I have the content of "Data.txt"

Row 1: ACB MMM
Row 2: Date High    Low Open    Close   Volume  Adjusted Close  Date    High    Low Open    Close   Volume  Adjusted Close
Row 3: 40000    10  12  16  17  1500    17.2    40002   12  11  14  12  1200    12.2
Row 4: 40001    17.2    14  15  16  2500    18  40003   13.2    12  13  13  2300    13      

Note: First and Second row is only strings with every string is separated by tab. From the third row, it is only numbers with every string is separated by tab.

I want to read from row 3 to store in array "data" and read row 1 to store in array "symbol".

Thank you for your help.

Here is my code as following link: http://www.mediafire.com/view/qfxtvj8sr022rff/Code.txt

Sen
  • 7
  • 1
  • 4
    This can be solved with a simple loop and an if statement. What have you tried? – MeetTitan Sep 03 '15 at 02:00
  • You are more likely to get help if you show what you've tried, tell what's working and what's not working, what are the expected results, and what are the observed results from the program. – R Sahu Sep 03 '15 at 02:18
  • General purpose line reader: http://stackoverflow.com/questions/7868936/read-file-line-by-line . Recommend steering away form using an array. Look at using [std::vector](http://en.cppreference.com/w/cpp/container/vector) instead. – user4581301 Sep 03 '15 at 02:18

1 Answers1

0

Use std::getline to read file line by line

#include <iostream>
#include <fstream>
#include <string>

. . .

ifstream file("Data.txt");
string line;
while (getline(file, line)) {
    . . .
}

Use std::stringstream to read from a string

#include <sstream>

stringstream ss(line);
ss >> . . .;
Shreevardhan
  • 12,233
  • 3
  • 36
  • 50