how to cin in c++ without pressing enter key.

suppose i want to get values from user during run-time which are 1 and 2 and put it in variables a and b;
but without use of enter;
user should type "1<space><space>2" and that should do the work;
is there a way of doing this?;
I think you can use getch() or cin.get() to get what you're looking for.
user should type "1<space><space>2" and that should do the work;
is there a way of doing this?;

Not in standard C++.
I am almost certain it is possible to do this, but really tricky and probably not worth the time and effort to figure out how.

So, the first thing you would need to do is figure out how to get the input of "1" and "2" put into variables "a" and "b". I am thinking if you stored user input into a string, and then convert that string into a char array, you would be able to check each value individually and therefore assign which ones you want into variables.

Now for the second bit, this is where it gets very tricky. So, "cin" is apart of the built in C++ library which means you would have to change how that works so that "enter" is no longer used for that function; however, I do not even think it is possible to change native C++ functions like that. Therefore, you would have to do something far more complicated: I am guessing the only way to do what you want would be to create your own C++ function in your own defined C++ library to handle receiving input the same way "cin" does but with using a different key besides "enter".
Could you just:

std::istream::getline(string, 1024, ' ');

?
Topic archived. No new replies allowed.