I've been having issues in a program involving cin.
My problem is that the first word of everything I input appears to be skipped, possibly because of the way the buffer is handled. I have seen similar posts regarding this but trying to apply their fixes to my code have so far failed. What is supposed to happen is the user inputs a name and that name gets stored in a text file with other entered data. However, it always drops the first word.
#include "string"
#include "stdafx.h"
string _name;
int main()
{
cout << "Choose a name" << endl;
getline(cin, _name);
cout << _name;
ofstream dat;
dat.open("data.txt");
dat << _name;
dat.close();
return 0;
}
This code is where the problem appears to be. I just can't get it to take the first word.