Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the usage of cin, cin.get (), cin.getline (), getline (), gets (), etc.

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

What this article shares with you is about the usage of cin, cin.get (), cin.getline (), getline (), gets () and other functions. The editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.

When learning C++, these input functions are a little confused; here is a summary, for my own review, I hope it will be helpful to the newcomers, and if there are any mistakes, I would like to ask you for advice (all the programs in this article are run through VC 6.0)

1 、 cin

2. Cin.get ()

3. Cin.getline ()

4. Getline ()

5. Gets ()

6. Getchar () attached: cin.ignore (); cin.get () / / skip a character, such as unwanted carriage return, space and other characters 1, cin > > usage 1: the most basic and most commonly used usage, enter a number: # include

Using namespace std

Main ()

{

Int a,b

Cin > > a > > b

Coutnoskipws > > input [j]; / / if you don't want to skip white space characters, use noskipws flow control usage 2: accept a string and end # include with "space", "TAB" and "enter"

Using namespace std

Main ()

{

Char a [20]

Cin > > a

Cout

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report