473,394 Members | 1,800 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

POSIX and getch(), clrscr()

Hi there,
I am using a POSIX-compliant system, Cygwin on Windows.

I need the features of conio.h's getch() and clrscr(), but I can't
compile programs with #include <conio.h(since conio.h is NOT POSIX).

I tried to implement myself clrscr() with system("cls"), but the program
compiles ok, but during the running it will show:

sh: cls: command not found

(on filecompiled.exe runned on Windows).

Is there away to implement clrscr() and getch() ?

Thank you

PS: a C++ program POSIX-compliant with advantages have? "Only" portability?
Any drawbacks?
Jul 20 '07 #1
8 5598
Michele 'xjp' a écrit :
Hi there,
I am using a POSIX-compliant system, Cygwin on Windows.

I need the features of conio.h's getch() and clrscr(), but I can't
compile programs with #include <conio.h(since conio.h is NOT POSIX).

I tried to implement myself clrscr() with system("cls"), but the program
compiles ok, but during the running it will show:

sh: cls: command not found

(on filecompiled.exe runned on Windows).

Is there away to implement clrscr() and getch() ?
getch() you cannot. This is due to the way terms are handled.
The same is true for clrscr().
A long time ago, printf( "\e[2J\e[H" ) did that but I don't expect it to
be portable.
PS: a C++ program POSIX-compliant with advantages have? "Only" portability?
Any drawbacks?
Portability on POSIX system only.

Michael
Jul 20 '07 #2
Michael DOUBEZ wrote:
Michele 'xjp' a écrit :
>Hi there,
I am using a POSIX-compliant system, Cygwin on Windows.
This should suggest to you that some POSIX or UNIX-group should be more
relevant for your question.
>I need the features of conio.h's getch() and clrscr(), but I can't
compile programs with #include <conio.h(since conio.h is NOT POSIX).
No. Perhaps you want some curses library. I believe Cygwin comes with a
ncurses port.
>I tried to implement myself clrscr() with system("cls"), but the program
compiles ok, but during the running it will show:

sh: cls: command not found

(on filecompiled.exe runned on Windows).

Is there away to implement clrscr() and getch() ?

getch() you cannot. This is due to the way terms are handled.
You would have to change the way terminals are handled. It is possible and
not very hard, but way off topic for this news group. The command 'man
termios' will give some info. Questions should be asked in a POSIX or UNIX
forum.
The same is true for clrscr().
A long time ago, printf( "\e[2J\e[H" ) did that but I don't expect it to
be portable.
The output codes _are_ standardised, but not in the C++ standard.

--
rbh
Jul 20 '07 #3
Michele 'xjp' wrote:
Hi there,
I am using a POSIX-compliant system, Cygwin on Windows.

I need the features of conio.h's getch() and clrscr(), but I can't
compile programs with #include <conio.h(since conio.h is NOT POSIX).
Everything here is off-topic. Try either the Cygwin mailing list, or
comp.unix.programmer.


Brian
Jul 20 '07 #4
On Jul 20, 11:30 am, Michele 'xjp' <mich...@removethis.nectarine.it>
wrote:
I am using a POSIX-compliant system, Cygwin on Windows.
This is the first I've heard that Cygwin is Posix compliant.
I need the features of conio.h's getch() and clrscr(), but I
can't compile programs with #include <conio.h(since conio.h
is NOT POSIX).
Is there away to implement clrscr() and getch() ?
Traditionally, under Unix, they are part of the curses library.
(I don't think this is Posix, but rather an Open Systems
extension to Posix.) Versions are available for Windows (under
the name ncurses, I think), so you can use it more or less
portably.
PS: a C++ program POSIX-compliant with advantages have? "Only"
portability? Any drawbacks?
The Windows Posix-compliant layer is only there for the show;
from what I hear, it's not really usable. The CygWin toolset
runs significantly slower than anything else under Windows
(including UWin or MSys), and I suspect (although I've not
verified) that this is due to some Unix-like intermediate layer.

In general, you can suppose that native Windows will run better
(faster, more reliably) under Windows than any Unix-like
emulation, and that native Unix will run better under Unix than
any Windows like emulation. The basic functionalities of the
two systems are, however, very, very similar (except maybe for
some of the threading primitives---although recent versions of
Windows also have Posix-like conditional variables), so it is
relatively simple to define a neutral interface, implement it
for both systems, and use it. In no case would I try to do
Posix under Windows (or vice versa).

--
James Kanze (Gabi Software) email: ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Jul 20 '07 #5
On Jul 20, 12:27 pm, Robert Bauck Hamar <roberth+n...@ifi.uio.no>
wrote:
Michael DOUBEZ wrote:
[...]
A long time ago, printf( "\e[2J\e[H" ) did that but I don't
expect it to be portable.
The output codes _are_ standardised, but not in the C++ standard.
The backslash escape codes are standardized in the C++ standard,
and "\e" is not one of them:-). He probably meant "\033" or
"\x1b". The meaning of such escape sequences is defined by
ISO/IEC 6429---an ISO standard, but not the C++ standard, as you
say. The correct escape sequence to clear the screen would be
"\033[2J"; whether this will actually do anything, of course,
depends on whether the target device is conform to the
appropriate standard, and not on whether the compiler is conform
to the C++ standard (or is even C++).

--
James Kanze (Gabi Software) email: ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Jul 20 '07 #6
James Kanze ha scritto:
On Jul 20, 11:30 am, Michele 'xjp' <mich...@removethis.nectarine.it>
wrote:
>I am using a POSIX-compliant system, Cygwin on Windows.

This is the first I've heard that Cygwin is Posix compliant.
>I need the features of conio.h's getch() and clrscr(), but I
can't compile programs with #include <conio.h(since conio.h
is NOT POSIX).
>Is there away to implement clrscr() and getch() ?

Traditionally, under Unix, they are part of the curses library.
(I don't think this is Posix, but rather an Open Systems
extension to Posix.) Versions are available for Windows (under
the name ncurses, I think), so you can use it more or less
portably.
However, I've implemented clrscr() with:
printf("\e[2J")

and getch-like with:
char tmp;
cout << "Press ENTER to continue" << endl;
cin >tmp;

Jul 21 '07 #7
On Jul 21, 3:08 pm, Michele 'xjp' <mich...@removethis.nectarine.it>
wrote:
James Kanze ha scritto:
On Jul 20, 11:30 am, Michele 'xjp' <mich...@removethis.nectarine.it>
wrote:
I am using a POSIX-compliant system, Cygwin on Windows.
This is the first I've heard that Cygwin is Posix compliant.
I need the features of conio.h's getch() and clrscr(), but I
can't compile programs with #include <conio.h(since conio.h
is NOT POSIX).
Is there away to implement clrscr() and getch() ?
Traditionally, under Unix, they are part of the curses library.
(I don't think this is Posix, but rather an Open Systems
extension to Posix.) Versions are available for Windows (under
the name ncurses, I think), so you can use it more or less
portably.
However, I've implemented clrscr() with:
printf("\e[2J")
It works on my system, too. Because my terminal windows are
always xterm's, and X (yet another standard) requires that xterm
implement ANSI escape sequences.

The curses library will ensure that it will work on any terminal
that the system supports.
and getch-like with:
char tmp;
cout << "Press ENTER to continue" << endl;
cin >tmp;
That doesn't do anything near the same thing. getch reads a
single character, immediately (without waiting for a new line),
and returns it without echoing.

--
James Kanze (Gabi Software) email: ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Jul 22 '07 #8
James Kanze <ja*********@gmail.comwrote:
It works on my system, too. Because my terminal windows are
always xterm's, and X (yet another standard) requires that xterm
implement ANSI escape sequences.
X doesn't require that.

xterm implemented a vt102 ~20 years ago just because it was the most
common type (but even then it implemented some other terminal's features).

most of vt102 is ANSI (say 80%).

--
Thomas E. Dickey
http://invisible-island.net
ftp://invisible-island.net
Jul 27 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: AHR | last post by:
Hi NG I am learning MFC but only use the command promt at the moment to run my C++ programs. My problem is that i cant use clrscr() even if i include <conio.h>. I get this error: ****
3
by: voidstar | last post by:
Hi, I have the following problem: I use "getch" to monitor keypresses and the I use "cin" to input a string. When I type in 'y', the 'y' character appears, so I need to hit backspace before...
5
by: Binny V A | last post by:
Hello Everyone, I have been programming in C++ with borland compiler for a while now. But when I try to compile the same programs with other complilers like mingw, digital mars etc. there are...
4
by: Crow | last post by:
Is there any way to make cin behave like getch()? Specifically, getch() returns immediately after a key is pressed and the cin family of input methods seem to block until a new line is...
1
by: Ratheesh Kumar | last post by:
My doubt is on the working of getch() function based on the following observations 1) if the pressed key has an ascii code,only that can be read using a single call to getch() 2) if the key has...
45
by: simnav | last post by:
In the following code something strange happens ! If I keep pressed any of ALT+Arrow, keys, they are extracted two times from buffer then getch seems to stop; if I release and press again ALT+arrow...
5
by: Sankar | last post by:
Dear all, In my programming snippet compiled in Linux 2.6, I have a getch() , but the program when executed does not wait for my input.. fflush(stdin), fflush(stdout) - All these did not help. ...
9
AmberJain
by: AmberJain | last post by:
Hello, What is the difference between --------> 1. clrscr(); // defined in various header files 2. system("cls"); //available in stdio.h in bloodshed dev c++ Well,...
16
by: fuzhen | last post by:
If I want to "press any key to continue" in Windows, I can use getch() But the getch() isn't a standard C function So what should I to do in Linux?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.