C++ 如何用cout輸出hex,oct,dec的解決方法
更新時(shí)間:2013年05月31日 10:40:32 作者:
本篇文章是對(duì)C++中如何用cout輸出hex,oct,dec的方法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
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語(yǔ)言如何實(shí)現(xiàn)兩數(shù)之和
這篇文章主要介紹了c語(yǔ)言如何實(shí)現(xiàn)兩數(shù)之和,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-07-07C++標(biāo)準(zhǔn)庫(kù)bitset類(lèi)型的簡(jiǎn)單使用方法介紹
這篇文章主要介紹了C++標(biāo)準(zhǔn)庫(kù)bitset類(lèi)型的簡(jiǎn)單使用方法,需要的朋友可以參考下2017-07-07C語(yǔ)言實(shí)現(xiàn)打印九九乘法表的四種方式小結(jié)
這篇文章主要為大家介紹了C語(yǔ)言實(shí)現(xiàn)打印九九乘法表的四種方式,文中的示例代碼講解詳細(xì),簡(jiǎn)潔易懂,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2023-07-07Matlab中圖像數(shù)字水印算法的原理與實(shí)現(xiàn)詳解
數(shù)字水印技術(shù)作為信息隱藏技術(shù)的一個(gè)重要分支,是將信息(水印)隱藏于數(shù)字圖像、視頻、音頻及文本文檔等數(shù)字媒體中,從而實(shí)現(xiàn)隱秘傳輸、存儲(chǔ)、標(biāo)注、身份識(shí)別、版權(quán)保護(hù)和防篡改等目的。本文就來(lái)講講圖像數(shù)字水印算法的原理與實(shí)現(xiàn),感興趣的可以了解一下2023-04-04C語(yǔ)言實(shí)現(xiàn)簡(jiǎn)單的停車(chē)場(chǎng)管理系統(tǒng)
這篇文章主要為大家詳細(xì)介紹了C語(yǔ)言實(shí)現(xiàn)簡(jiǎn)單的停車(chē)場(chǎng)管理系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-03-03c語(yǔ)言詳解動(dòng)態(tài)內(nèi)存分配及常見(jiàn)錯(cuò)誤的解決
給數(shù)組分配多大的內(nèi)存空間?你是否和初學(xué)C時(shí)的我一樣,有過(guò)這樣的疑問(wèn)。這一期就來(lái)聊一聊動(dòng)態(tài)內(nèi)存的分配,讀完這篇文章,你可能對(duì)內(nèi)存的分配有一個(gè)更好的理解2022-04-04C++ 內(nèi)聯(lián)函數(shù)inline案例詳解
這篇文章主要介紹了C++ 內(nèi)聯(lián)函數(shù)inline案例詳解,本篇文章通過(guò)簡(jiǎn)要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下2021-09-09