Reading file into object array C++ -
I have to read from a data file that is formatted like this
abcd (string) 1 ( Int. 2 (Int) 3 (Int) - ABCDE (String) 4 (Int) 3 (Int) 2 (Int)
.
.
.
I want to do some functions that only use the variable in the same line but here is my code. I am starting because so please thank me right.
In the .h file
#include & lt; String & gt; using namespace std; #ifndef CALC_H # defined CALC_H class calc {public: Read Zero file (string file); Private: The name of the string; Int a; Int b; Int c; }; #endif in the implementation file #include "vehicle.h" include # iostream & gt; # Include fstream & gt; # String & gt; Include # include cstdlib & gt; # Include & gt; using namespace std; Zero vehicle :: readFile (string filename) {ifstream myIn; Ent Qulanum = 0; MyIn.open (filename.c_str ()); If (! My in) {cerr & lt; & Lt; "Failed to open data file! \ N"; Exit (0); } For (int i = 0; i And then I want to read that file
for (int i = 0; i & lt; MAX; i ++) Cout & lt; & Lt; Calc [Ii] .name & lt; & Lt; Calc [I]. A & LT; & Lt; Calc [i] .b & lt; & Lt; Calc [I]. C & LT; & Lt; Endl; Sorry I left out a lot of stuff, I just want to know that I'm on the right track. Thanks
The proper way to do this is by & gt; & Gt; operator Calc for your class. Category Calc {Public: Buddy Island & amp; Operator & gt; & Gt; (Istream and My, Calc and Calc); }; IStream & amp; Operator & gt; & Gt; (Istream and MyE, Calc, and Calc) {myIn & gt; & Gt; Calc.name; My In & gt; & Gt; Calc.a; My In & gt; & Gt; Calc.b; My In & gt; & Gt; Calc.c; Make me return; } Now you can do this:
while (myIn>> calc [i]) {++ TotalNum; }
Comments
Post a Comment