1、输出
#include<bits/stdc++.h>
using namespace std;
int main(){
cout<<"Hello world"<<endl;
//等价于
//cout<<"Hello world";
//cout<<endl;//回车换行
//连续输出
cout<<"Hello"<<" "<<"world"<<endl;
return 0;
}
Hello world
Hello world
2、变量的输出
int main(){
int a = 10;
float b =3.14;
char c = 'C';//字符类型赋值是单引号
string d = "Doing";
bool e = right;
cout<<"a="<<a<<endl;
cout<<"b="<<b<<endl;
cout<<c<<" "<<d<<" "<<e<<endl;
return 0;
}
a=10
b=3.14
C Doing 1
3、类型转换
int main(){
double a = 1.1;
string aa = "123";
int b = (int)a;
int bb = stoi(aa);//字符类型转换为int类型
cout<<b<<" "<<bb<<" "<<b+bb<<endl;
//int转换为string
string aaa = to_string(b);
string bbb = to_string(bb);
cout<<aaa+bbb<<endl;
return 0;
}
1 123 124
1123