Compile error for cout<<fixed;

Write here if you have problems with your C++ source code

Moderator: Board moderators

Post Reply
samee_zahur
New poster
Posts: 2
Joined: Mon Sep 19, 2005 3:26 pm

Compile error for cout<<fixed;

Post by samee_zahur » Mon Sep 19, 2005 3:33 pm

The usual C++ alternative for the C code:

printf("%.3lf",1.2);

is something like:

cout<<fixed<<setprecision(3)<<1.2;

or without #include<iomanip>,

cout<<fixed; cout.precision(3);
cout<<1.2;

However, these C++ versions does not seem to compile at the online judge compiler, even though these are very much (ISO) standard compliant. I'm not sure if these were included in the ARM, but pretty sure that they are in the iostream library.

Can somebody please clarify this issue for me?

Samee

User avatar
Cho
A great helper
Posts: 274
Joined: Wed Oct 20, 2004 11:51 pm
Location: Hong Kong

Post by Cho » Mon Sep 19, 2005 3:43 pm

You should do something like:

Code: Select all

#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
   double x=1.2;
   cout << setprecision(3) << setiosflags(ios::fixed) << x << endl;
   return 0;
}

samee_zahur
New poster
Posts: 2
Joined: Mon Sep 19, 2005 3:26 pm

Post by samee_zahur » Mon Sep 19, 2005 6:32 pm

Thanks for the advice ... but that's quite a long line for a simple task, wouldn't you say? Specially when the cout<<fixed is standard compatible (As far as I know) ... seems like an overkill. Can anyone tell me why it is rejected?

Samee

Post Reply

Return to “C++”