C++ 如何用cout輸出hex,oct,dec的解決方法
更新時間:2013年05月31日 10:40:32 作者:
本篇文章是對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/C++獲取主機(jī)網(wǎng)卡MAC地址的三方法
MAC地址(Media Access Control address),又稱為物理地址或硬件地址,是網(wǎng)絡(luò)適配器(網(wǎng)卡)在制造時被分配的全球唯一的48位地址,通過獲取MAC地址可以判斷當(dāng)前主機(jī)的唯一性可以與IP地址綁定并實現(xiàn)網(wǎng)絡(luò)準(zhǔn)入控制,本文給大家介紹了使用C/C++獲取主機(jī)網(wǎng)卡MAC地址的三方法2023-11-11
C語言數(shù)據(jù)類型枚舉enum全面詳解示例教程
生活中有很多地方會用到枚舉,比如一周有7天,可以一一枚舉;性別有男、女...等等都可以可以一一枚舉,今天來和筆者一起學(xué)習(xí)一下c語言枚舉吧2021-10-10
Windows下sentry接入C/C++程序的詳細(xì)過程
sentry作為一個開源的軟件,發(fā)展至今,已經(jīng)非常成熟。它支持的平臺眾多,甚至于針對不同的工作者(后臺、前端、客戶端)都有相應(yīng)的內(nèi)容,這篇文章主要介紹了Windows下sentry接入C/C++程序,需要的朋友可以參考下2022-09-09
C語言中pthread_exit()函數(shù)實現(xiàn)終止線程
本文主要介紹了C語言中pthread_exit()函數(shù)實現(xiàn)終止線程,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-05-05

