整数的基数:dec(十进制) , oct(八进制), hex(十六进制) 。
具体实现见代码:
/**************************************************/
#include <iostream>
using namespace std;
int main()
{
cout.setf(ios::hex, ios::basefield); //十六进制
cout << 100; // this displays 64
return 0;
}
/**************************************************/
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int n;
cout << "Enter a decimal number: "; //输入一个十进制的数
cin >> n;
cout << n << " in hexadecimal is: " //用十六进制表示为
<< hex << n << '\n'
<< dec << n << " in octal is: " //用八进制表示为
<< oct << n << '\n'
<< setbase( 10 ) << n << " in decimal is: " //十进制表示为
<< n << endl;
return 0;
}
/**************************************************/
/********以整数开方为例介cin、cout中设置精度的用法************/
/*
设置浮点数精度:
setprecision (必须带参数)
precision (无参数时返回当前设置的精度)
设置后,对以后的输出都有效。
*/
#include<iostream>
#include<ctype.h>
#include<iomanip>
#include<cmath>
using namespace std;
int main() {
double ans=sqrt(3.0);
cout<<setiosflags(ios ::fixed)
<<"Square root of 2 with precisions 0-9\n"
<<"precision se by the "
<<"precision member function:"<<endl;
for(int i=0; i<=9; i++) {
cout.precision(i);
cout<<ans<<endl;
}
cout<<"precision now is: "<<cout.precision()<<endl;
for(int i=0; i<=9; i++) {
cout<<setprecision(i)<<ans<<endl;
}
return 0;
}
/**************************************************/
基本都是根据别人的分享总结的,不是很全,以后会更新的。。。。