I have a question similar to the one posted here:
C++: Read from text file and separate into variable
The difference is that the original post had the file.txt in the following format:
- name int int int
- name int int int
My file has the following format:
fname lname
int int int
fname lname
int int int
I am trying to read the name in (first and last) and store it to a single variable and each int into its own separate variable (for future calculations).
I have tried using something similar to the answer, but the newlines are messing up my variables.
As an added bonus, there are random blank lines in my file.
Here is the code I have so far
if (myfile.is_open())
{
while (getline(myfile, line))
{
istringstream iss(line);
string fname;
string lname;
if (line != "")
{
iss >> fname >> lname >> x >> y >> z >> a >> b >> c;
cout << "name: " << fname << endl;
//iss >> x >> y >> z >> a >> b >> c;
cout << "x: " << x << "y: " << y << endl;
}
else cout << "";
}
}