setprecision and fixed

#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!!
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
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
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
I thought that 'fixed' was defined in the include file <cmath>
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.