C++ input and output notes summary

  • 2020-04-02 02:41:34
  • OfStack

This paper summarizes the C++ input and output of a variety of considerations for C++ beginners or C++ programmers have a certain reference value. The specific summary and analysis are as follows:

I. string class:

1. Cin > > When a string is encountered, the '\n' or space stops, and the '\n' or space remains in the input, i.e. only a word is read or nothing is read, but the string class handles the empty characters and so on.

2. Getline (cin,string) can be used to read a line into the string. This function reads until it encounters '\n'.

Second, the char arr [] :  

1. Cin > > Arr will always read in, not safe. When it encounters '\n' or space, it stops and adds '\0' automatically, but '\n' or space remains in the input.

2. Read a line with cin. Getline (arr,length) and add '\0' at the end to specify the length. Read '\n' and discard.

Three, char:

1. Cin > > Char skips '\n' or Spaces until it doesn't.

2. Cin. Get (char) can read every character, including line breaks and Spaces.

Read a line from the file to string:     Getline (ifstream,string); Here getline is just a function.


Related articles: