C++ 如何用cout輸出hex,oct,dec的解決方法
更新時間:2013年05月31日 10:40:32 作者:
本篇文章是對C++中如何用cout輸出hex,oct,dec的方法進行了詳細的分析介紹,需要的朋友參考下
HEX:
#include <iostream.h>
#include <iomanip.H>
main(void)
{
long n = 10000;
cout << hex << n ;
return 0;
}
OCT:
#include <iostream.h>
#include <iomanip.H>
main(void)
{
long n = 10000;
cout << oct << n ;
return 0;
}
DEC:
#include <iostream.h>
#include <iomanip.H>
main(void)
{
long n = 10000;
cout << dec << n << endl;
return 0;
}
#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;
}
復(fù)制代碼 代碼如下:
#include <iostream.h>
#include <iomanip.H>
main(void)
{
long n = 10000;
cout << hex << n ;
return 0;
}
OCT:
復(fù)制代碼 代碼如下:
#include <iostream.h>
#include <iomanip.H>
main(void)
{
long n = 10000;
cout << oct << n ;
return 0;
}
DEC:
復(fù)制代碼 代碼如下:
#include <iostream.h>
#include <iomanip.H>
main(void)
{
long n = 10000;
cout << dec << n << endl;
return 0;
}
復(fù)制代碼 代碼如下:
#include <iostream>
using namespace std;
int main()
{
cout.setf(ios::hex, ios::basefield);
cout << 100; // this displays 64
return 0;
}
復(fù)制代碼 代碼如下:
#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;
}
相關(guān)文章
C語言實現(xiàn)打印九九乘法表的四種方式小結(jié)
這篇文章主要為大家介紹了C語言實現(xiàn)打印九九乘法表的四種方式,文中的示例代碼講解詳細,簡潔易懂,感興趣的小伙伴可以跟隨小編一起學習一下2023-07-07
Matlab中圖像數(shù)字水印算法的原理與實現(xiàn)詳解
數(shù)字水印技術(shù)作為信息隱藏技術(shù)的一個重要分支,是將信息(水印)隱藏于數(shù)字圖像、視頻、音頻及文本文檔等數(shù)字媒體中,從而實現(xiàn)隱秘傳輸、存儲、標注、身份識別、版權(quán)保護和防篡改等目的。本文就來講講圖像數(shù)字水印算法的原理與實現(xiàn),感興趣的可以了解一下2023-04-04
C++ 內(nèi)聯(lián)函數(shù)inline案例詳解
這篇文章主要介紹了C++ 內(nèi)聯(lián)函數(shù)inline案例詳解,本篇文章通過簡要的案例,講解了該項技術(shù)的了解與使用,以下就是詳細內(nèi)容,需要的朋友可以參考下2021-09-09

