Currently trying to store some information from a text file, the text file is in the format of number/text/text/number, and I want to save them as an int, string, string, and a float respectively. In the file they are actually separated by a /, so an example of the text file could look like 173/hello/goodbye/13.4
This is the code I have so far
int main(){
string menuname;
int a;
float d;
string b;
string c;
bool error = false;
ifstream openFile;
do{
cout << "Please enter the name of the menu you would like to open: ";
cin >> menuname;
menuname += ".txt";
openFile.open(menuname.c_str());
if(openFile.fail()){
cerr << "Unable to open file, please re-enter the name.\n";
error = true;
}
}while(error == true);
openFile >> a;
openFile >> b;
openFile >> c;
openFile >> d;
cout << itemno << category;
}
I'm not 100% sure what is causing the issue, but I have a feeling it could be to do with the string, as if i just use openFile >> a;
with the next 3 it shows correctly, but after adding openFile >> b;
it shows the whole line instead of just the word/phrase next to it.