So, I have the text file that looks like this:
3434343434343 3434343434343 sam THOMAS
and I want to save each item into seperate variables. till now I have done:
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
using namespace std;
int main() {
string nd, st;
long long C,N;
ifstream myfile("input.txt");
if (myfile.is_open())
{
while (!myfile.eof())
{
myfile >> C;
myfile >> N;
myfile >> nd;
myfile >> st;
cout << C << N << nd << st <<endl;
}
myfile.close();
}
else cout << "Unable to open file";
return 0;
}
I get 3434343434343 3434343434343 sam THOMAS 3434343434343 3434343434343 sam THOMAS Press any key to continue . . . Why do I get 1 extra lines?