any good tutorials on console commands?

Started by
3 comments, last by Beowulf_ 21 years, 5 months ago
Hi, I''m working on programming my first c++ console game, and there are alot of things I''d like to be able to do, but I''m not sure how. For example: -I want to be able to prompt the user for a single char, and then once they press a key, read the char and continue, as opposed to waiting for them to press enter. -On a very related note, I want to have a "press any key to continue" command. Anyone know how to do this, or a good tutorial?
Advertisement
Well... as you''re using c++, here is a reeeeeeeaaaaalllllyyyy simple program that combines those two things:



  #include <iostream.h>#include <conio.h>void main(){	char c1;	cout << "Char -> ";	cin >> c1;	cout << "Char was " << c1 << endl;	cout << "Press any key to continue..." << endl;	getch();	cout << "Finish...Bye...";}  



if you''re looking for tutorials, there''s nothing a search with google can''t solve:

http://www.google.com/search?hl=en&ie=UTF-8&oe=UTF-8&q=c%2B%2B+tutorial



Bye


a) It depends on your platform - C++ has no notion of keyboard or console, only streams, and the standard behaviour of the run-time library is to wait for a carriage return before providing the data to the streams.

b) On MS platforms, look at the conio.h header. On Unix platform, look at the ncurses.h header.

c) Don''t ever use <iostream.h> - despite the fact that many C++ books use it, it is not a C++ header. Use <iostream>

Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Hey thanks for the help, one problem though.

When I use the getch() command, it makes the screen go blank. When a key is pressed, everything re-appears.
Nevermind. I figured it out. You have to flush the output buffer first.

This topic is closed to new replies.

Advertisement