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     - ntop monitoring software configuration and installation (Linux)

- ORA-04031 error appears in the solution run utlrp.sql (Database)

- Hadoop upload files error solved (Server)

- ISO image to use offline upgrade Ubuntu (Linux)

- Install the latest Eclipse IDE in Ubuntu (Linux)

- Terminal fun: 6 interesting Linux command-line tools (Linux)

- Oracle users to automatically increase the partition table (Database)

- CentOS 6.7 install Nagios Tutorials (Server)

- Linux (Debian) install software, missing dynamic link libraries .so (Linux)

- Learning MySQL data types (Database)

- MySQL bulk insert data script (Database)

- MySQL various log summary (Database)

- Supervisor Installation and Configuration (Server)

- Using Android Studio integrated development environment to build Android (Linux)

- PostgreSQL use pgpool achieve high availability (Database)

- MySQL + Heartbeat + DRBD deployment architecture (Server)

- C ++ stderr / stdout redirected to a file (Programming)

- Oracle11g Trigger Debugging Record Error: PLS-00201: identifier SYS.DBMS_SYSTEM 'must be declared (Database)

- Build a super simple "hardware" firewall router (Linux)

- Linux kernel programming parameter passing between modules and function calls (Programming)

  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);
- Linux smart small switch rfkill (Linux)
- zBackup: A versatile tool to remove duplicate backup (Linux)
- Bash mathematical extension (Programming)
- Linux command in the dialog whiptail (Linux)
- Installation and configuration under Linux SVN server - Backup - Recovery - Scheduled Tasks (Server)
- How to Install Android Studio on Ubuntu 15.04 / CentOS7 (Linux)
- Ubuntu 14.10 Install Ubuntu Touch Music App 2.0 (Linux)
- Sqoop data export import command (Database)
- Git Advanced Tutorial (Linux)
- MySQL and MariaDB traditional master-slave cluster configuration (Database)
- Linux Crontab Timing task command Detailed (Linux)
- To install PostgreSQL 9.4 (Database)
- Linux file system structure Introduction (Linux)
- RM Environment Database RMAN Backup Strategy Formulation (Database)
- How to forcibly change the Linux system password on a regular basis (Linux)
- MySQL primary and secondary replicate data inconsistencies (Database)
- Using PPA to install the lightweight theme software HotShots 2.1.0 under Ubuntu (Linux)
- Observation network performance tools for Linux (Linux)
- To create a file in Linux directory by setfacl (Linux)
- C ++ you can become a new scripting language (Programming)
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.