语言(一)
一、语言
C++(GNU G++17)
//代码模板 #include <bits/stdc++.h> using namespace std; int main() {
return 0; }
二、头文件
#include<bits/stdc++.h>
三、输入输出
(1)
int n; cin>>n; cout<<n<<endl;
(2)
int n; scanf("%d",&n); printf("%d\n",n);
(3)使用cin输入数据较多时
std::ios::sync_with_stdio(false); std::cin.tie(0);
(4)输出小数时控制位数
//头文件#include<iomanip> double d=3.1415926; //1_保留小数点后两位 printf("%.2lf\n",d); //2_1_保留小数点后两位 cout.setf(ios::fixed); cout<<fixed<<setprecision(2)<<d<<endl; //取消保留小数后位数 cout.unsetf(ios::fixed); //2_2_保留两位有效数字 cout<<setprecision(2)<<d<<endl;
四、交互式问题
int n; cout<<n<<endl; cout<<flush;//刷新缓冲区 /*************************/ printf("%d\n",n); fflush(stdout);//刷新缓冲区

浙公网安备 33010602011771号