- Code: Select all
#include <iostream>
#include <string>
using namespace std;
int main()
{
string address;
cout << "Enter you address" << endl;
getline(cin,address,'\n');
//with a delimiter specified
//getline(cin,address,'\n');
cout << "You are residing at " << address << endl;
return 0;
}
this is a piece of code i got from http://cplus.about.com/library/weekly/aa030702a.htm.
When I tried out this code, I entered:
555 Elm St.
then hit enter.
Nothing happens after i hit the first enter.
I hit enter again for a 2nd time...
the output finally comes out: " You are residing at 555 Elm St."
How do i fix it so that I only have to press enter once? I tried specifying the delimeter to be \n but same results occurred.
