* How to getline when you have used cin >> char?
@ 2002-09-02 18:35 weihui qiu
2002-09-02 18:57 ` Jeff Sturm
0 siblings, 1 reply; 2+ messages in thread
From: weihui qiu @ 2002-09-02 18:35 UTC (permalink / raw)
To: gcc
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: How to getline when you have used cin >> char?
2002-09-02 18:35 How to getline when you have used cin >> char? weihui qiu
@ 2002-09-02 18:57 ` Jeff Sturm
0 siblings, 0 replies; 2+ messages in thread
From: Jeff Sturm @ 2002-09-02 18:57 UTC (permalink / raw)
To: weihui qiu; +Cc: gcc
On Mon, 2 Sep 2002, weihui qiu wrote:
> 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!!
Not strange at all. Read about stty and raw vs. cooked tty input.
Your question is off-topic for this list since it has nothing to do with
development of g++.
Jeff
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2002-09-03 1:57 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-09-02 18:35 How to getline when you have used cin >> char? weihui qiu
2002-09-02 18:57 ` Jeff Sturm
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).