#include <iostream>
#include <iomanip>
int main()
{
double temp_price;
std::cout << "Price?\n> "; //12345.6789
std::cin >> temp_price;
// **** don't do this
// std::cout << "Price\t\t >> " << std::cout.setf(std::ios::fixed) << std::cout.precision(4) << temp_price << " <<" << std::endl;
// this is fine
std::cout << "Price\t\t >> " << std::fixed << std::setprecision(4) << temp_price << " <<" << std::endl;
// this would also have been fine
std::cout.setf(std::ios::fixed) ;
std::cout.precision(4) ;
std::cout << "Price\t\t >> " << std::fixed << std::setprecision(4) << temp_price << " <<" << std::endl;
}
> Any thoughts why this is happening?
std::cout.setf(std::ios::fixed) returns the old format flags (ones before the call to the function). std::cout.precision(4) returns the old precision (the precision before the function was called).
These two values get printed (if the format flags are of some output streamable type).