This is my first time on this website so bear with me. I am a novice c++ programmer as well.
I'll get straight to the point.
I'm trying to read an input file with a multiple data, but its not outputting properly. I'll give you small example of my problem. Basically within this file I have 3 separate strings listed on the same line (from left to right)
BNA Boston Red Stockings NA
The three separate strings are: BNA, Boston Red Stockings, and NA
The fact that Boston Red Stockings has 2 whitespaces makes it difficult for me. I can't just use getline because there is different string right after that on the same line NA, which would store Boston Red Stockings NA into string two which is not what I want. I want Boston Red Stockings stored into string two and NA stored into string three. I tried to be as explicit as possible. Any help would be appreciated. Thanks.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
string id, name, active;
ifstream inFile;
inFile.open("test.dat");
inFile >> id;
getline(inFile, name);
inFile >> active;
cout << endl << id << endl << name << endl << active << endl << endl;
system("pause");
return 0;
}
Here is the text file line:
BNA Boston Red Stockings NA