setprecision and fixed

Aug 12, 2010 at 11:39am
#include<iostream>
#inlcude<iomanip>
using namespcae std;
int main()
{
float a=3.14;
cout<<fixed<<setprecision(4)<<a;
}
if i execute the above code i am getting the error: fixed undeclared...
need some help.. pls!!
Aug 12, 2010 at 12:08pm
fixed is undeclared, obviously, this means that the variable "fixed" does not exist in your code, yet you try to use it. If you want to know how to solve this issue read this http://cplusplus.com/doc/tutorial/

you also misspelled namespace
Last edited on Aug 12, 2010 at 12:09pm
Aug 12, 2010 at 8:26pm
you also misspelled namespace


another reason for why you should not use general namespaces, but just stuff like std:: or using std::

and as skilless said, you never declared fixed. So you should add something to your code like
float fixed; // or any other variable type really
Aug 13, 2010 at 10:32am
Aug 13, 2010 at 11:19am
Ow.
learn something new every day =p

well then he would have to do something like
1
2
3
4
5
6
7
8
9
#include<iostream>

using namespace std;
int main()
{
    float a=3.14;
    cout.precision(4)
    cout<<fixed<<a;
}
Last edited on Aug 13, 2010 at 11:20am
Aug 14, 2010 at 7:17am
I thought that 'fixed' was defined in the include file <cmath>
Aug 14, 2010 at 12:36pm
hi ,
i am sorry..i didnt notice that i misspelled namespace while posting my question...
actually i saw the following link http://www.cplusplus.com/reference/iostream/manipulators/setprecision/
and tried it in the same way...

#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
float a=3.14;
cout<<fixed<<setprecision(4)<<a;
}

so my output should be:3.1400.
but when i execute the above code.. i am getting the error as fixed undeclared...

Topic archived. No new replies allowed.