| vichu8888 (176) | |||||||||
|
Hi all, I have input file which contains a transaction details. Each line have 5 data, date,code,activity,shares,price for example:
how do i read it and store it in respective variables say
What I have done so far is
This code works fine. But is there any simpler way to read and store the variables. Because im storing the values into variables directly declared in the class ex and Date date1. Im not at all using set methods used. for example I have a set method for shares
How do i use this set method during the reading function
| |||||||||
|
|
|||||||||
| strongdrink (444) | |
|
Pass a pointer of your input stream to the set_code method. EDIT: I recommend not actually using the input stream in the setters, instead, have a 'load' method, which you pass an input stream to, which will parse the data and stick in the corresponding variables. | |
|
Last edited on
|
|
| vichu8888 (176) | |||||
|
Thanks for the advice strongdrink. What I did now is I declared variables
in the main itself and using sstream i stored each values into its variables. Then I call the set methods of the classes and set it.
Will that be efficient? | |||||
|
|
|||||
| jlb (77) | |||
I myself would read an entire line from the file into a std::string. Then have a "setter" function that takes this string and fills in the data members, from the string using string streams. For example:
| |||
|
|
|||
| vichu8888 (176) | |
| thanks jlb. thats look better choice | |
|
|
|