Home PC Games Linux Windows Database Network Programming Server Mobile  
  Home \ Programming \ How to use the character in C ++ without pressing the Enter key to enter the Show     - CentOS card fails to start at boot progress bar certmonger solve (Linux)

- How to adjust the system time CentOS (Linux)

- Varnish configuration language VCL and its built-in variables (Server)

- Go Languages Reviews (Programming)

- ElasticSearch basic usage and cluster structures (Server)

- Shuffle Process Arrangement in MapReduce (Server)

- Visual Studio Code experience (Linux)

- OpenDJ installed on RHEL6 (Linux)

- Linux how to view the graphics models notebook (Linux)

- C ++ Learning Notes: references (Programming)

- Java transient keyword (Programming)

- linux raid levels and concepts introduced (Linux)

- Use PDFBox processing PDF documents (Linux)

- EXP-00091: Exporting questionable statistics Processing Method (Database)

- CentOS 6.5 configuration SSDB 1.8.0 (Server)

- How do I delete a NEEDS RECOVERY rollback state of undo tablespace (Database)

- Java programmers talk about those advanced knowledge and direction (Programming)

- CoreOS use register mirror to build private warehouse (Linux)

- LAMP and LNMP automated installation scripts (Server)

- BackTrack (BT3, BT4) Linux installation tutorial (Linux)

  How to use the character in C ++ without pressing the Enter key to enter the Show
  Add Date : 2018-11-21      
  Question as follows:
Adam: because it is not often used, so I can never remember how to implement this function. In the C / C ++, and not to the next line (press enter) is obtained from standard input and what is the best method of character is it?

Also, if the characters do not have to type in the screen that is certainly the most perfect, but I just can not imagine been knocked Console (Enter) to get keyboard input.

Some answers:
Best one, from Johannes Schaub - litb:

      If only pure C ++, then it is unlikely to meet the portability, because it is largely dependent on the terminal being used, in which the terminal is connected to stdin (usually line buffered). But you can use some libraries to perform this function:

        Under 1.Windows compiler is available conio. Use _getch () function so you do not wait for a carriage return character input can be obtained. I do not often use the Windows development environment to develop, but I've seen my classmates just include the header file conio.h ready for use. You can find conio.h in Wikipedia. The above lists getch (), declared as deprecated (deprecated) in in Visual C ++.

          2.Linux development environment can be used in curses, it can also be used in Windows-compatible curses implementation. Compared to conio It also has a getch () function. (You can view its manpage by man getch). Similarly, you can also find Curses on Wikipedia.

If you intend to make your program run cross-platform, I recommend you use curses. However, I believe there is something you can use to turn off the function line buffer (I believe it should be called "raw mode", and "processing mode", can be viewed in detail in the man stty). Curses can help you deal with this in cross-terminal cross-platform environment.

Sone of codes:

From Kay:
This code uses kbhit () Check whether the keyboard is pressed, and obtain input characters using getch ().

#include < conio.h>
if (kbhit ()! = 0) {
  cout < < getch () < < endl;

From Falcon Momot:

Linux (or other UNIX systems) can be achieved in:

#include < unistd.h>
#include < termios.h>
char getch () {
      char buf = 0;
      struct termios old = {0};
      if (tcgetattr (0, & old) < 0)
              perror ( "tcsetattr ()");
      old.c_lflag & = ~ ICANON;
      old.c_lflag & = ~ ECHO;
      old.c_cc [VMIN] = 1;
      old.c_cc [VTIME] = 0;
      if (tcsetattr (0, TCSANOW, & old) < 0)
              perror ( "tcsetattr ICANON");
      if (read (0, & buf, 1) < 0)
              perror ( "read ()");
      old.c_lflag | = ICANON;
      old.c_lflag | = ECHO;
      if (tcsetattr (0, TCSADRAIN, & old) < 0)
              perror ( "tcsetattr ~ ICANON");
      return (buf);
- Oracle lag () and lpad () function (Database)
- Android float ball and boot from the start (Programming)
- How Bluetooth turned off by default in Ubuntu 14.04 (Linux)
- The Linux-based security settings Ipchains Firewall (Linux)
- Default permissions Linux file and directory permissions and hide - umask, chattr, lsattr, SUID, SGID, SBIT, file (Linux)
- 3 ways to create a lightweight, durable system of Ubuntu Linux USB disk (Linux)
- 10046 trace only open for a particular SQL statement (Database)
- Boost notes --Thread - problems encountered in the initial use on Ubuntu (Programming)
- LVM basic concepts, management (Linux)
- UNIX and class UNIX system security check notes (Linux)
- SQL Server automatic backup script (Database)
- Ubuntu achieve initialization iptables (Linux)
- C ++ virtual functions Classic Insights (Programming)
- Linux configuration Samba server (Server)
- Linux System Getting Started Tutorial: Five image processing software (Linux)
- Cooling solutions Ubuntu system (Linux)
- Wildcards and special symbols usage comments under Linux (Linux)
- Into the Java keyword instanceof (Programming)
- Ubuntu 15.10 / 14.04 install subtitling software Aegisub (Linux)
- LinSSID: a graphical Wi-Fi scanner under Linux (Linux)
  CopyRight 2002-2020 newfreesoft.com, All Rights Reserved.