I want a function like getch ()
I know conio.h it's not a standard header and why I want another function
sorry for mistakes(I'm not English)->google translate
I want a function like getch ()
I know conio.h it's not a standard header and why I want another function
sorry for mistakes(I'm not English)->google translate
Code:#include <cmath> #include <complex> bool euler_flip(bool value) { return std::pow ( std::complex<float>(std::exp(1.0)), std::complex<float>(0, 1) * std::complex<float>(std::atan(1.0) *(1 << (value + 2))) ).real() < 0; }
SO,I have to use getch()
thanks anyway
but equivalent to clrscr () , I do think not exists in header
"system("cls");" is good?
Last edited by nutzu2010; 12-29-2010 at 12:01 PM.
No, you should tell us which operating system and compiler you're using, so you can use the most appropriate "this works like getch() in conio.h"
Using it isn't a problem, so long as you know it isn't portable.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
windows xp2,codeblocks with mingw
you mean the getch () or system ("cls")?Using it isn't a problem, so long as you know it isn't portable.
Both. Personally, I would wrap any non-standard function calls in another function, for clarity (and maintainability).
[edit]
Example:
[/edit]Code:#ifdef WIN32 #include <conio.h> #endif int unbuffered_input( void ) { #ifdef WIN32 return getch( ); #else #error "fatal: 'unbuffered_input' not yet implemented for this system" #endif } void clear_screen( void ) { #ifdef WIN32 system( "cls" ); #else #error "fatal: 'clear_screen' not yet implemented for this system" #endif }
Last edited by Sebastiani; 12-29-2010 at 12:53 PM.
Code:#include <cmath> #include <complex> bool euler_flip(bool value) { return std::pow ( std::complex<float>(std::exp(1.0)), std::complex<float>(0, 1) * std::complex<float>(std::atan(1.0) *(1 << (value + 2))) ).real() < 0; }
There is a win32 "getch" replacement in the FAQ.
There's a tutorial for win32 consoles here -> adrianxw.dk Win32 Tutorials Home
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
For clearing a screen, try printing a form feed character, like so:
I know this works on Linux, but I'm not sure about Windows. It can't be any less portable than system("cls").Code:putchar('\f');
@Sebastiani good code ,but should be included "stdlib.h"
i found here an exemplu about "win32" and I understand.
@Salem tansks for FAQ ,but I do not understand how to install PDcurses
@anduril462 your exemple does not work(probably ,is only for linux)
I think I'll use the solution of Sebastiani or " system("cls") and getch() "
Last edited by nutzu2010; 12-30-2010 at 03:03 AM.
If you're going to use Sebastiani's code with the #else portion, you might as well put something other than ""fatal: 'clear_screen' not yet implemented for this system". You can use the putchar I gave you or use system("clear") to support Linux and the like:
Code:void clear_screen( void ) { #ifdef WIN32 system( "cls" ); #else system( "clear" ); #endif }
Wonderful code,@anduril462!!!
Thank you all for your answers!