I am just learning about output and input from .txt files using #include<fstream>. I'm having quite a bit of trouble understanding how to get certain things in my .txt file to display to the console. I'm having to do it in a table format which I don't have trouble with but I can't even really get started because I'm having trouble understanding. I know how to read from a file and write to a file. But not how to read certain items in the .txt file to display them to console.
I'm reading from this input file order.txt.
My orders.txt file looks like this:
Turn on the Bright Lights
Interpol
9.49
House of Jealous Lovers
The Rapture
1.29
Fever to Tell
Yeah Yeah Yeahs
6.99
Desperate Youth, Blood Thirsty Babes
TV on the Radio
8.91
The Fragile
Nine Inch Nails
12.49
So it has title, artist, and price of download. I've been reading my book and my notes but I only know how to do inFile if it's the same kind of data like all numbers or all characters. Not when it's all mixed together like this.
I want to give you all an example of what I have done so far but I really don't have much because I can't figure out how to start this.
Do I need to be using while loops or for statements here?
Any help would be appreciated, thank you very much :D
Okay so this is what I have so far. It is a mess. Because I have no idea what I'm doing with the input. I need it to read the titles, the artists, and the cost. As you can see I am doing this so wrong. There's 15 lines in the .txt file.
I've read things and seen videos and looked at examples but none explain how to do this. We haven't even covered arrays yet so I don't know how to make it read the lines in my orders.txt file. I know how to make it read all the way to the end of the text but I don't think that's what I'm looking for here.
I'm sorry if this is a pain or stupid question, I just have no idea. :/
Well now I've done a while loop but because of the way the .txt file is structured with having mostly long names with spaces it doesn't handle it well. I don't know what to do.
Do you realize that the extraction operator>> stops processing the string when it encounters a whitespace character? Since your strings have spaces perhaps you should consider getline()?