This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
How to getline when you have used cin >> char?
- From: weihui qiu <weihuiq at yahoo dot com>
- To: gcc at gnu dot org
- Date: Mon, 2 Sep 2002 18:35:27 -0700 (PDT)
- Subject: How to getline when you have used cin >> char?
Hi,
There is a strange behavior about g++ compiler under
unix system. When I first cin >> char and then
cin.getline(char*, int), it don't wait for me to input
a line, but directly execute the next line. How to
solve this problem? Please help me!!
Regards!
Weihui
leo:~/adv_str/hw1 > cat try.cxx
#include <iostream>
using namespace std;
int main () {
char c;
cout << "Input a char!!";
cin >> c;
cout << c << endl;
char* line = new char[1000];
cout << "Please input sentence: " << endl;
cin.getline(line, 1000);
cout << line << endl;
cout << "Input a char!!";
cin >> c;
cout << c << endl;
return 0;
}
leo:~/adv_str/hw1 >
leo:~/adv_str/hw1 > g++ try.cxx
leo:~/adv_str/hw1 > a.out
Input a char!!c
c
Please input sentence:
//Here don't wait for input!!!
Input a char!!a
a
leo:~/adv_str/hw1 >
__________________________________________________
Do You Yahoo!?
Yahoo! Finance - Get real-time stock quotes
http://finance.yahoo.com