About get and getline in C + +

Source: Internet
Author: User

1 Cin encounters a space return will end the input so it cannot be completed 12 34 such a one-time input

2 getline () and get () both functions read one line of input, however, getline () discards the line break

and get () keeps line breaks in the input sequence

Simple example:

1 cin.getline (name,20);//reads the input into the name array of length 20

2 Cin.get (name,10);

Cin.get (name1,10);

After the first call, the line break is left in the input queue, so the first character seen by the second call is a line break.

So get () thought it had reached the end of the line, so that no readable content was found

That means you can do it like this:

Cin.get (name,10);

Cin.get ();//Read line break

Cin.get (name1,10);

About get and getline in C + +

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.