2023 5 5

xuxingkai / 2023-05-06 / 原文

#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
    int a;
    cout << "请输入a:";
    cin >> a;
    cout << "十进制:" << dec << a << endl;
    cout << "十六进制:" << hex << a << endl;
    cout << "八进制:" << setbase(8) << a << endl;
    string ps = "China";
    cout << setw(10) << ps << endl;
    cout << setfill('*') << setw(10) << ps << endl;
    double p = 22.0 / 7.0;
    cout << setiosflags(ios::scientific) << setprecision(8);
    cout << "p=" << p;
    cout << "p=" << setprecision(4) << p << endl;
    return 0;
}

 

#include <iostream>
using namespace std;
int main()
{
    int a = 21;
    cout.setf(ios::showbase);
    cout << a << endl;
    cout.unsetf(ios::dec);
    cout.setf(ios::hex);
    cout << a << endl;
    cout.unsetf(ios::hex);
    cout.setf(ios::oct);
    cout << a << endl;
    cout.unsetf(ios::oct);
    string p = "China";
    cout.width(10);
    cout << p << endl;
    cout.width(10);
    cout.fill('*');
    cout << p << endl;
    double ps = 3.1415;
    cout.setf(ios::scientific);
    cout << ps << endl;
    cout.width(14);
    cout << ps << endl;
    cout.unsetf(ios::scientific);
    cout.setf(ios::fixed);
    cout.width(12);
    cout.setf(ios::showpos);
    cout.setf(ios::internal);
    cout.precision(6);
    cout << ps << endl;
    return 0;
}

 

 

#include <iostream>
using namespace std;
int main()
{
    char p[] = "BASIC";
    for (int i = 4; i >= 0; i--)
        cout.put(*(p + i));
    cout.put('\n');
    return 0;
}