C++: Reading from text file with numbers and strings

vinhhuynh

New Member
My text file has structure in file "data.txt":
(1) Row 1: Symbol of Stocks.
(2) Row 2: Header of data.
(3) From Row 3: Only data in numbers.
I can just read the number data when I delete Row 1 and 2, following my code in "code.txt".
My purpose is reading all string data in row 1 and number data from row 3 to store in two separate arrays: Array SYMBOL to store symbol, and Array DATA to store number data but don't delete row 1 and row 2.

Thank you for your help.
Vinh Huynh
 

Attachments

Daniel Duffy

C++ author, trainer
What's the question?
edit: I am guessing you want to know how to do it?

in C++ you could use

. streams
. boost matrices
. C++11 regex

for example.

BTW seems to be a memory leak in your code.
 
Last edited:

vinhhuynh

New Member
Hi Daniel Duffy, I am not good at C++ file handling with numbers and strings. I supposed you can edit my code. One more request is that do you know any article or book that guides to handling with data (inputs) ? It means that guides code in C++ to get data from text document (.txt) or excel file or any other storage file.
Thank you very much.
Vinh Huynh
 

Daniel Duffy

C++ author, trainer
Hi Daniel Duffy, I am not good at C++ file handling with numbers and strings. I supposed you can edit my code. One more request is that do you know any article or book that guides to handling with data (inputs) ? It means that guides code in C++ to get data from text document (.txt) or excel file or any other storage file.
Thank you very much.
Vinh Huynh
This is almost impossible given your current C++ level. I would search for packages that do this for you.

Off the top of my head, this package might be useful
Gawk for Windows
 
My purpose is reading all string data in row 1 and number data from row 3 to store in two separate arrays: Array SYMBOL to store symbol, and Array DATA to store number data but don't delete row 1 and row 2.
Why are you trying to store the string data in a double?
Make 2 separate arrays and store accordingly (detect data type).
 
Top