The native meaning of the operator << is to shift left bitwise, for example: 1 <<2; its meaning is to shift the integer 1 to the left by 2 bits, that is:
0000 0001 ->0000 0100
Overload the left shift operator to left shift a variable or constant into an object.
# include<iostream>
const char endl= '\n';
class Console
{
public:
Console& operator << (int i)
{
cout<< i<<endl;
return *this;
}
Console operator <<(char c)
{
cout<<c<<endl;
return *this;
}
Console operator<<(const char* s)
{
cout<<s<<endl;
return *this;
}
Console& operator<<(double d)
{
cout<<d;
return *this;
}
};
Console cost;
intmain()
{
cout<<1<<endl; // cout.operator<<(1);
cout<<" sdlfj"<<endl;
double a=0.1;
double b=0.2;
cout<<a+b<<endl;
return 0;
}
The c++ standard library is not part of the c++ language. The c++ standard library is a collection of class libraries and function libraries. The classes and objects defined in the c++ standard library are located in the std namespace, and the header files of the c++ standard library do not have the .h suffix. , the c++ standard library covers the functions of the c library.
#include<stdio.h> // c compatible library
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
using namespace std;
intmain()
{
char* p =(char*)malloc(16); / / #include<cstdlib>
strcpy(p,"sdjfl") ;
free(p);
}
The C++ Standard Library contains implementations of classical algorithms and data structures.