i am trying to get this very simple program working . program runs it print out ‘Please, enter your full name: ‘ . i enter my name with space ‘john johnny'(ignore ”for reference only) then i enter delimiter $ and press enter key . program was supposed to stop at cin.get(); so that i can read the output but program the closes . help me out i am very newb in it
this is the code
#include <iostream>
#include <string>
using namespace std ;
void main ()
{
string name;
cout << "Please, enter your full name: ";
getline (cin,name,'$');
cout << "Hello, " << name ;
cin.get();
}
The new line character, that was entered by the user after the
$, will remain in the input stream as it will not have been consumed bygetline(): this is the character thatget()reads.Just use
getline, using new line as delimiter (the default).