zoukankan      html  css  js  c++  java
  • 第十周项目1-程序填充与阅读(二)

    /*
     *Copyright (c) 2014,烟台大学计算机学院
     *All gight reserved.
     *文件名称:temp.cpp
     *作者:邵帅
     *完成时间:2014年10月30日
     *版本号:v1.0
     *
     *问题描述:
     *输入描述:
     *程序输出;
    */
    #include <iostream>
    #include <iomanip>//不要忘记包含此头文件
    using namespace std;
    int main()
    {
        int a=34;
        cout<<"hex:"<<hex<<a<<endl;
        cout<<"oct:"<<setbase(8)<<a<<endl;
        cout<<"dec:"<<dec<<a<<endl;
        char *pt="China";
        cout<<setw(10)<<pt<<endl;
        cout<<setfill('*')<<setw(10)<<pt<<endl;
        double d=225.0/7.0;
        cout<<"d="<<d<<endl;
        cout<<"d="<<setprecision(4)<<d<<endl;
        cout<<"d="<<setiosflags(ios::fixed)<<d<<endl;
        cout<<setprecision(5)<<d<<endl;
        return 0;
    }

    程序分析:

    hex:设置数值的基数为16


    dec:设置数值的基数为10


    oct:设置数值的基数为8


    setw(10):设置字符宽度为10位


    setfill('*'):设置填充字符*


    setprecision(4):设置浮点数的精度为4位

    setiosflags(ios::fixed):设置浮点数以固定的小数位显示



    这些还真得好好的去记一下~


    @ Mayuko


  • 相关阅读:
    231. Power of Two
    204. Count Primes
    205. Isomorphic Strings
    203. Remove Linked List Elements
    179. Largest Number
    922. Sort Array By Parity II
    350. Intersection of Two Arrays II
    242. Valid Anagram
    164. Maximum Gap
    147. Insertion Sort List
  • 原文地址:https://www.cnblogs.com/mayuko/p/4567648.html
Copyright © 2011-2022 走看看