example2_manipulators.cpp

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
#include <iostream>
#include <iomanip>

int main() {
    double pi = 3.14159265358979323846;
    
    std::cout << "Default output: " << pi << std::endl;
    std::cout << "Fixed precision (3): " << std::fixed << std::setprecision(3) << pi << std::endl;
    std::cout << "Scientific notation: " << std::scientific << pi << std::endl;
    std::cout << "Hexadecimal: " << std::hex << std::uppercase << std::setw(10) << std::setfill('0') << 255 << std::endl;

    return 0;
}
Back to input-output