This is the first day of my participation in the August More Text challenge
The code for this series of C++ articles is the C++98 standard
C++ is a compiled, general-purpose, case-sensitive programming language that fully supports object-oriented development.
Basic I/O
Cin and cout
In C, the standard keyboard input and screen output functions are implemented using scanf() and printf() respectively. The input stream class istream and output stream class ostream are provided in the C++ library. Cin and cout are objects of the Istream and Ostream classes, respectively, for basic keyboard input and screen output.
The < < and > >
The operation of getting data from an input stream is called an extract operation, and the operation of adding data to an output stream is called an insert operation. The operators “>>” and “<<” are shift operators, but “>>” and “<<” have been overridden in the C++ library header files as stream extract operators and stream insert operators, respectively, to input and output C++ standard types of data.
In C++, you can use the stream extraction operator “>>” to get data from the standard input device keyboard. For example, the statement “cin>>x;” Get input data from the keyboard and assign to variable X. With CIN you can get multiple input values from the keyboard. Cout is a standard output stream object that outputs information to the output device screen using the stream insertion operator “<<“. When cin and cout are used in your program, you need to include header files in your program. Note that both the stream extract and stream insert operators consist of two consecutive symbols, with no other symbols in between.
User-defined data cannot be directly input or output with << and >>, but can be used only after the operators of << and >> are overloaded.
The general format of CIN is as follows:
cin>>var1>>var2>>... >>varn;Copy the code
The general format of cOUT is as follows:
cout<<var1<<var2<<... <<varn;Copy the code
Say Hello is implemented using basic input and output
#include <iostream> #include <string> using namespace std; int main(){ string name; Cout <<" Enter your name "<<endl; cin>>name; cout<<"Hello "<<name<<endl; return 0; }Copy the code
Endl is short for end line, which means to end the current line and enter to wrap the line. Output:
Type your name RidingRoad Hello RidingRoadCopy the code