My program reads first name then last name in another line, while I need it to read first and last name together

You can also try like below,

cout << " Reading from txt file" << endl;

ifstream file("file.txt");

string content;

int i = 0;

while (file >> content) {

    cout << content << ' ';

    i++;

    if (i == 2)

    {cout<<endl;i=0;}

}

system("pause");

return 0;

Leave a Comment