c++ - input from txt file to arrays -
After
I have a text file with a line like:
James 10 Motor Vehicles Max] [NAME_MAX]. Int yearorre [max]; Four departments [Max] [DEP_MAX]; Double perere [max]; While (i & lt; MAX & infile) {infile.getline (Name Array [i], 20); Infile & gt; & Gt; YearArray [i]; Infile.getline (sectionaries [i], 15); Infile & gt; & Gt; PayArray [i]; Cout & lt; & Lt; Nominal [i] & lt; & Lt; "" & Lt; & Lt; Year old [i] & lt; & Lt; "" & Lt; & Lt; Departments [i] & lt; & Lt; "" & Lt; & Lt; Fixed & lt; & Lt; Setcrison (2) & lt; & Lt; Peaurere [i] & lt; & Lt; Endl; I ++; } The code is only trying to do what you do to me, but when I run this, I get cut down to give an idea of something like that: < / P>
James Dean-858 99 3460-92559631349317830000000000000000000000000000000000000000000000.00
Thanks for the help.
==== Edit ====================================== ====== I have to use and not >> to get it >> Because some lines I'm reading are more than just "James Dean", they last up to 20 years ... East : "William K. Woodward" is another one
So, if I just get used to, then it reads the first line in the right, but then I get a second text mess in the same line
Here is the code:
infile.get (named Array [i], 20); Infile & gt; & Gt; YearArray [i]; Infile.get (Departments [i], 15); Infile & gt; & Gt; PayArray [i];
After takes an input stream and a string getline To write, two getline calls are read in two lines, your input mechanism is broken either, getline or stream extraction operator (i.e. > ; & Gt; ), but neither
If you plan to use the getline , then you need to parse the string (which effectively passes one line of input), and then type them correctly. Must archive in the array. There are second and fourth token numbers, so you will need to change them from string to int or double .
Operator & gt; & Gt; approach:
string name, surname; Int year; double payment; While (Infile) {infile> & Gt; Name & gt; & Gt; Surname & gt; & Gt; Year & gt; & Gt; Department & gt; & Gt; the wages; Nominal [i] = name + "+ + nickname; // para ray [i] = pay; ++ i;}
getline approach :
string line; while (gateline (infel, line)) {pars (line, token); nominal [i] = token [0] + "token [1]; // ... payare [i] = strotod double (token [4]); ++ i; } // Parse Definition Zero Pars (string line, vector & lt; string & gt; and token) {// roll your own} double stratos double (strings) {// ...}
Comments
Post a Comment