开发者

C++ Input Stream

I have a program that work with data which is paste to console. For example when the program is run and I paste

delete 54545
add 4324

the program call delete function with parameter 54545, but wait for enter after 4324 to call second function. And I have no idea how to call it without press enter.

example

first line is how many functions should call. and I paste this at console

3
delete 4324324
add 324
add 4324

the code is like that

...
int count;
string func, parameter;
cin >> count;
for (int i=1; i<=count;i++) {
    cin >> func;
    switch(func) {
       case "add": cin >> parameter; add(parameter); break;
       case "delete": cin >> parameter; delete(parameter); break;
    }
}
...

all function is called but the last one is not... in this example last function is add and the program wait to press enter after

case "add": cin >> parameter

to call function开发者_如何学Go.


If you need to process input supplied by the user and do not want to wait with parsing until the user presses enter, you cannot use standard streams for that.

Insead getch() function might work for you, please note hovewer that this is not standard C/C++.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜