Hi, I have written the following code to input data from a text file, My question is how to modify the input to accept a ful line for the 'Firt Line ' parameter
E.g at the moment it only takes the first word of each string, like this:
Vol Chapter First line
One One Once
One Two Meanwhile
I want it to go like this:
Vol Chapter First line
One One Once upon a time
One Two Meanwhile in the garden
I tried the following code, which seems to work, but duplicates the last entry. Iknow I can be crude and just delete the last array entry, but I was wondering if there is a proper way to do it?
You may want to consider getting the complete line with getline() for every line of text within your file, then use a stringstream to parse the line as required.
1 2 3 4 5 6 7 8 9 10
ifstream mfile("Books.txt");
string line;
size_t x = 0;
while( getline(mfile, line)){
list.push_back(temp);
stringstream ins(line);
ins >> list[x].Vol >> list[x].Chp;
getline(ins >> ws, list[x].FLine); // Get the remainder of the line.
x++;
}
Also I recommend you stop putting multiple statements on the same line. Do this makes your programs harder to read, harder to follow the program logic, and harder to debug. When you have multiple statements on the same line and you have a logic problem your debugger won't be able to distinguish between the statements.