How to use cin in C++
This article mainly shows you "how to use cin in C++". The content is simple and clear. I hope it can help you solve your doubts. Let the editor lead you to study and learn how to use cin in C++.
Preface
In C++, cin is generally used to interact with each other to obtain user input information. Cin is the standard input stream object in C++ programming language, that is, the object of stream class. Cin is mainly used to read data from standard input, which refers to the keyboard of the terminal. Cin > >, cin.get () and cin.getline () are mainly used. When cin reads data, it also obtains data from the buffer. When the buffer is empty, the member function of cin will block waiting for the data to arrive. Once there is data in the buffer, it will trigger the member function of cin to read the data.
1. Cin1, cin > >
Continuous reading is supported, with Tab and space as delimiters and newline characters as closing symbols
/ *-> File Name: cinDemo01.cpp > Author: Jxiepc > Mail: Jxiepc > Created Time: Mon 20 Sep 2021 10:09:55 AM CST- -- * / # include#include#includeint main (int argc Char * argv []) {std::string s While (std::cin > > s) {when std::cout reads data from the cache, it automatically ignores Tab, Space, and line feeds that exist as the first character, continues to read the next character, and waits if the cache is empty. However, if the read is successful, the delimiter after the character is left in the buffer and cin > > is not processed.
2. Cin.get ()
Read characters, including spaces
/ *-> File Name: cinGetDemo.cpp > Author: Jxiepc > Mail: Jxiepc > Created Time: Mon 20 Sep 2021 10:20:59 AM CST- -* / # include#include#include#includevoid test02 () {char str [256] Std::cout