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?

Recommended Answers

All 3 Replies

std::ios::fixed Just add the std:: in front

...Oh.

Thanks.

#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
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.