- c++统一初始化
int main()
{
int a = 10;
int b(10);
int c{10};
int ar[10] ={1,2,3,4,5,6,7,8,9,10};
int br[10]{1,2,3,4,5,6,7,8,9,10};
return 0;
}
2.c++采用标准输入输出流
#include<iostream>
using namespace std;
int main()
{
int a = 0;
char ch = ' 0';
cin>>a>>ch; // cin 输入流对象
cout<<"a = "<<a<<" ch = "<<ch<<endl; // cout 输出流对象
return 0;
}
// cin 输入流对象 , 键盘
// cout 输出流对象 , 控制台(屏幕)
// >> 提取符
// << 插入符
// endl => '\n'; 换行符
总结:
使用cout标准输出(控制台)和cin标准输入(键盘)时,必须包含< iostream >头文件以及std标准命名
空间。endl 相当于 ' /n';
输入字符串:
#include<iostream>
using namespace std;
int main()
{
const int n = 128;
char str[n];
cin>str; // 输入 hello c++
cout<<str<<endl; // hello
cin.getline(str,n); // hello c++
cout<<str<<end; // hello c++
cin.getline(str,n,'#'); // hello c++ # world
cout<<str<<endl; // hello c++
return 0;
}