How to accept a full name with spaces

Apr 19, 2017 at 11:00pm
So this is a pretty simple question, I just can't find info on reading in a string which has a space using getline. The syntax I've tried for my program is
getline(cin, mystring, '\n'), but that doesn't seem to work. The program just ignores the rest of what is supposed to be inputted and exits.

1
2
3
4
5
6
7
8
9
10
11

void Individual_Entry::set_name()
{
	string name_entry;
	
	cin.ignore();
	cout << "Please enter the name: ";
	getline(cin, name_entry, '\n');
	this->name = name_entry;
}
Last edited on Apr 19, 2017 at 11:26pm
Apr 19, 2017 at 11:13pm
try to post only that bit of code that is relevant for your problem, now where in your 150 lines do i look for what you are seeking help on?
Apr 19, 2017 at 11:28pm
My bad, edited it down to the function. I need to know why my program is going haywire if I try to enter two separate names of a full name in one line when getline should be working. The program works fine with a singular name.
Apr 20, 2017 at 2:35am
Anyone? This is a pretty simple error, I just don't know the syntax for fixing it.
Apr 20, 2017 at 2:51am
remove the newline character from getline() else it's left in the input stream:

Explicit delimiting character: The operation of extracting successive characters stops as soon as the next character to extract compares equal to this.

http://www.cplusplus.com/reference/istream/istream/getline/
Topic archived. No new replies allowed.