including <ios>

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

Moderator: Board moderators

Post Reply
Dzhefri
New poster
Posts: 8
Joined: Mon May 15, 2006 8:46 am

including <ios>

Post by Dzhefri »

In one of the files that I've submitted, I wrote

Code: Select all

    ostringstream o;
    o << fixed << setprecision(3);
I made sure to include

Code: Select all

#include <iomanip>
#include <sstream>
#include <string>
#include <cmath>
#include <vector>
#include <iostream>
using namespace std;
And this all worked perfectly fine on my machine at home, and it certainly seems to be in line with how I've seen 'fixed' described in all the reference books I can find. However, the compiler tells me:

04585573_24.c: In method `class string circle_equation::as_string_1()':
04585573_24.c:24: `fixed' undeclared (first use this function)
04585573_24.c:24: (Each undeclared identifier is reported only once
04585573_24.c:24: for each function it appears in.)

So I look up in my reference books what I should include to make sure that the compiler knows what 'fixed' is, and add the line

Code: Select all

#include <ios>
After adding this line to my program and compiling it on my machine here, everything still worked just fine. When I submitted it, however, I got yet another error message:

04585578_24.c:1: ios: No such file or directory

Well, I'm fresh out of ideas. Can anybody tell me how to get the compiler to compile my code?

fpavetic
Learning poster
Posts: 51
Joined: Sat Mar 04, 2006 8:00 pm

Post by fpavetic »

write
ostringstream o;
o << ios::fixed << setprecision(3);
that should work

Dzhefri
New poster
Posts: 8
Joined: Mon May 15, 2006 8:46 am

Post by Dzhefri »

Well, I tried that, and it compiled on both my machine and on the compiler there. However, it said that my program gave the wrong answer, so I try running the program on my computer. The correct output should look like

(x - 17.716)^2 + (y - 0.735)^2 = 15.733^2
x^2 + y^2 - 35.433x - 1.470y + 66.865 = 0

(this is problem #190), and that's what my old version of the program (which compiles on my machine but not on the submit-o-matic machine) produced. Strangely enough, after I added ios:: to fixed, it gave this output:

4(x - 17.7)^2 + (y - 0.735)^2 = 15.7^2
4x^2 + y^2 - 35.4x - 1.47y + 66.9 = 0

So now, instead of having 3 digits after the decimal, it has 3 significant digits, and there's a mysterious '4' at the front of the string.

Curiouser and curiouser...

fpavetic
Learning poster
Posts: 51
Joined: Sat Mar 04, 2006 8:00 pm

Post by fpavetic »

sorry, i have written that without thinking, what i have written up there has outputed value of ios::fixed:
this should be correct now :)

ostringstream o;
o.setf( ios::fixed );
o << setprecision( 3 ) << nubmeryouwanttoprint;

Dzhefri
New poster
Posts: 8
Joined: Mon May 15, 2006 8:46 am

Post by Dzhefri »

Yes, that worked! Thank you!

But do you have any idea why the other way way wouldn't work? Is this a problem with the submit-o-matic compiler or with my own compiler?

chunyi81
A great helper
Posts: 293
Joined: Sat Jun 21, 2003 4:19 am
Location: Singapore

Post by chunyi81 »

The judge's compiler is very old and cannot support some C++ IO manipulation flags

Post Reply

Return to “C++”