#include <iostream>
#include <iomanip>
using namespace std;
// namespace:命名空间的关键字
// std:系统的关键字
int main()
{
cout << "输入" << endl
<< "int,char,double" << endl;
int num = 0;
char ch = 0;
double val = 0.0;
cin >> num >> ch >> val;
cout << "num = " << num << " ch = " << ch << " val = " << val << endl;
cout << "***********************" << endl;
cout << "oct:" << oct << num << endl;
cout << "hex:" << hex << num << endl;
cout << "dec:" << dec << num << endl;
cout << "***********************" << endl;
cout << setbase(8) << num << " " << setbase(16) << num << " " << setbase(10) << num << " " << endl;
cout << "***********************" << endl;
cout << setw(10) << "num =" << num << endl; // 右对齐
cout << left << setw(10) << "num =" << num << endl; // 左对齐
cout << setw(10) << setfill('*') << "num =" << num << endl; // 补全
cout << "***********************" << endl;
val = 3.14159265358;
cout << "val = " << val << endl; // 默认6位
cout << setprecision(2) << "val = " << val << endl; // 2位有效数字
cout << fixed << setprecision(2) << "val = " << val << endl; // 2位小数
return 0;
}
C++系列学习笔记
最新推荐文章于 2024-11-04 09:49:03 发布