Sysop: | Amessyroom |
---|---|
Location: | Fayetteville, NC |
Users: | 21 |
Nodes: | 6 (0 / 6) |
Uptime: | 31:50:38 |
Calls: | 139 |
Files: | 91 |
Messages: | 42,748 |
Hi all, I've been dealing with a problem for quite some time and was wondering if someone could help me with this. I have written a program that is currently under development and has not been released because it's far from a public beta release. Anyway, I use std::cin to ask for input from a menu of different option. My question is this. Dealing with portability to compile both in Linux and DOS, I need to be able to just enter one character from the keyboard to issue a command without hitting the enter key or a carriage return. How would I code the input portion after a menu of commands has been displayed on the console?---
Hi all, I've been dealing with a problem for quite some time and was wondering if someone could help me with this. I have written a program that is currently under development and has not been released because it's far from a public beta release. Anyway, I use std::cin to ask for input from a menu of different option. My question is this. Dealing with portability to compile both in Linux and DOS, I need to be able to just enter one character from the keyboard to issue a command without hitting the enter key or a carriage return. How would I code the input portion after a menu of commands has been displayed on the console?
I don't think such a function exists in standard C++ or C.
One thing you could do is to write your own function for inputting a character from the user and implement it differently, depending on which platform you're compiling on. You'd have the function decleared in a header file, and you can have the implementation in separate .cpp files (one for each platform), or a single .cpp file with pre-processor diretives around th implementations so you can give the pre-processor the appropriate flag, and it would compile the appropriate code in the .cpp file.
In Win32, there may be functions provided that do this. This page on Microsoft's MSDN site describes ReadConsole() - I haven't used this, but it may do what you want (although it looks a bit more complicated to use than cin):
http://msdn.microsoft.com/en-us/library/ms684958%28VS.85%29.aspx
The Linux implementation could use the nCurses library. nCurses has functions for getting a single character, such as getch(), wgetch(), etc.: http://www.mkssoftware.com/docs/man3/curs_getch.3.asp
I hope this helps.
...I think in Visual Studio, i'm a little foggy, but conio useta be present as of 6.0.. so you can #include <conio.h> i think in more recent version
then just calling getch() would get a hotkey.
That may work in Windows, but I believe Jon Justvig is working in Linux and wants his door to at least work in Linux. For a multi-platform solution, th are ways to use the appropriate function depending on which platform you're using.
used the DevC++, and sorta riped out their conio.h and included it in my own
used the DevC++, and sorta riped out their conio.h and included it in my
I love Bloodshed Dev++, works great for me.