Mega Code Archive

 
Categories / C++ Tutorial / Development
 

Using stream-manipulator showbase to show number base

#include <iostream> using std::cout; using std::endl; using std::hex; using std::oct; using std::showbase; int main() {    int x = 100;    cout << "Printing integers preceded by their base:" << endl << showbase;    cout << x << endl; // print decimal value    cout << oct << x << endl; // print octal value    cout << hex << x << endl; // print hexadecimal value    return 0; } Printing integers preceded by their base: 100 0144 0x64