C2039 'setprecision' not a member of std

I am a beginning programmer. I am doing a program for class and keep getting error codes C2039, C2873, and C3861 all having to do with setprecision. I am using #include <iomanip>. I have tried rearranging everything and searching the web but still cannot figure out the problem. The code is below. Can anyone help me?

Thanks
Regina



#include <iostream>
using std::cin;
using std::cout;
using std::endl;
using std::fixed;

#include <iomanip> // parameterized stream manipulators
using std::setprecision; // sets numeric output precision

#include "Program3_Wages.h" // include definition of class Wages from Wages.h

// function to calculate wages
void Wages::calculateWages()
{
double hours; // total hours worked
double rate; // hourly pay rate
double salary; // gross pay

// processing phase
// get first employee's hours worked
cout << "Enter hours worked (-1 to end): ";
cin >> hours;

// set floating-point number format
cout << fixed << setprecision( 2 );

// place your while loop here
// loop until sentinel value read from user
while ( hours != -1 ) // while hours are not -1
{
// get double rate
cout << "Enter hourly pay rate: "; // prompt for input
cin >> rate; // input next hourly pay rate
salary = hours * rate; // determines gross pay

} // end while

} // end function calculateWages
I could compile both compiler: bcc 5.5 and g++ / mingw 4.4 and I didn't get error messages. What kind of compiler do you use?
I am using Visual C++ 2008 Express Edition
Which project template did you start from?
I am not sure this is what you mean, but I used win32concsole application. Here is the header file and second source file that was provided for me.

// Program #3 Assignment #4 Object Interface: Program3_Wages.h
// Definition of class Wages that calculates wages.
// Member functions are defined in Program3_Wages.cpp
// (Interface separate from implementation!)

// Wages class definition
class Wages
{
public:
void calculateWages(); // function to calculate wages
// Note: Expecting no arguments (values) coming in
// and no value returned to caller
}; // end class Wages


// Program #3 Assignment #4 Solution: Program3_Client.cpp
// Create Wages object and invoke its calculateWages function.


#include "Program3_Wages.h" // include definition of class Wages from Program3_Wages.h

int main()
{
Wages myWages; // create Wages object myWages

myWages.calculateWages(); // call it's calculateWages function (Note: No arguments sent, and no value to be returned!)

return 0; // indicate program ended successfully

} // end main



Last edited on
your stuff compiles ok under 2005. i started with File->New->Project->General->Empty Project. after that, I added new .cpp items and an .h item.

i don't know if it does anything. salary isn't directed to any output. your hours loop never exits. i guess the work hours never end? very deep.
you haven't included the <iomanip> header which is what contains the setPrecision function. Always include the headers where the tool you use is defined. Don't rely on <iostream> including it for you otherwise you will get inconsistent results depending on the compiler.
http://cplusplus.com/reference/iostream/manipulators/setprecision/
Thanks for your help everyone. I finally got the problem solved.
Topic archived. No new replies allowed.