std::dec














































std::dec



ios_base& dec (ios_base& str);
Use decimal base
Sets the basefield format flag for the str stream to dec.

std::dec: When basefield is set to dec, integer values inserted into the stream are expressed in decimal base (i.e., radix 10). For input streams, extracted values are also expected to be expressed in decimal base when this flag is set.

std::oct : When basefield is set to octal, integer values inserted into the stream are expressed in octal base (i.e., radix 8). For input streams, extracted values are also expected to be expressed in octal base when this flag is set.

std::hex : When basefield is set to hex, integer values inserted into the stream are expressed in hexadecimal base (i.e., radix 16). For input streams, extracted values are also expected to be expressed in hexadecimal base when this flag is set.

For example:

#include<iostream>//std::cout, std::dec, std::hex, std::oct
  
int main() {
    int n = 54;
    std::cout<<std::dec<<"dec: "<< n <<endl;
    std::cout<<std::oct<<"oct: "<< n <<endl;
    std::cout<<std::hex<<"hex: "<< n <<endl;
    return 0;
}

Output:

dec: 54
oct: 66
hex: 36










More Articles of More Rakesh:

Name Views Likes
std::dec 457 1
std::clog 723 1
std::scanf 539 0
std::fixed 3370 0
std::freopen 532 0
std::fclose 287 1
std::cerr and std::wcerr 764 0
Std:cout 400 1
std::fprintf() 580 0
std::setw and std::setfill 1148 0
std::defaultfloat 602 0
std::endl 245 0
std::cin 293 1
std::fread() 645 0
std::fopen() 615 1

Comments

  • Aleggin
    8-Sep-2023 02:29:03 PM
    The basefield format flag is set for the str stream using just fall the C++ manipulator dec function. Integer values put into the stream are represented in decimal base (radix 10), when basefield is set to dec.

  • Paula
    4-Aug-2023 10:50:31 AM
    For me, it was very difficult to use std::dec to modify the default numeric base for integer I/O. You can take a look at this example and see if I'm doing it right. I am new to C++.
    std::cout << std::dec << 42;
    I want an output 42 in decimal format for angry gran project. Hope it is good.