0

Hey guys,

I've been having some trouble setting ios:: flags. In general I don't use using , but without it what I do doesn't work.

#include <iostream>
#include <iomanip>
using namespace std;

int main() {

	double moneys = 5.2;
	cout << "$" << moneys << "\n" << "$";
	cout << setiosflags(ios::fixed) << setprecision(2) << moneys;

	return 0;
}

#if (0)
#include <iostream>
#include <iomanip>

int main() {

	double moneys = 5.2;
	std::cout << "$" << moneys << "\n" << "$";
	std::cout << std::setiosflags(ios::fixed) << std::setprecision(2) << moneys;

	return 0;
}
#endif

First part does what I want done, #if block is my attempt without using and doesn't work. Any tips?

3
Contributors
3
Replies
4
Views
9 Years
Discussion Span
Last Post by vijayan121
0
#include <iostream>
#include <iomanip>

int main()
{
   // std::cout << std::setiosflags(std::ios::fixed) 
   //        << 22.6 << '\n' ;
   std::cout << std::fixed << 22.6 << '\n' ; // easier
   
   // std::cout << std::setiosflags(std::ios::hex) 
   //        << 34 << '\n' ;
   std::cout << std::hex << 34 << '\n' ; // easier
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.