Thread: setw not declared in this scope

  1. #1
    Registered User
    Join Date
    Feb 2011
    Posts
    5

    Smile setw not declared in this scope

    Hello I'm having an issue with my code when trying to manipulate my output. My program consists of main.cpp, StudentType.cpp, and StudentType.h. My problem is occuring in StudentType.cpp in this section:

    Code:
    void StudentType::printData(std::ostream& out){
      out << setw(15) << name;
      for (int i=0; i<NUM_GRADES; ++i){
        out << setw(3) << grades[i];
      }
      out << setw(5) << fixed << setprecision(2) << average << std::endl;
    }
    I thought including iomanip would fix it but it did not. I tried to include it in main and in StudentType.cpp and still get the error "setw is not declared in this scope". Any help would be very much appreciated.

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    setw is in namespace std.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  3. #3
    Registered User
    Join Date
    Feb 2011
    Posts
    5
    I changed it so that it says std::setw and it gives me the error "setw is not a member of std"

  4. #4
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Did you include <iomanip>
    Tim S

  5. #5
    Registered User
    Join Date
    Feb 2011
    Posts
    5
    Ah, I needed to include iomanip and also put std::, I kept doing one or the other. Thank you, it's working now.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. error: was not declared in this scope compilation error
    By i_r_tomash in forum C Programming
    Replies: 2
    Last Post: 05-27-2010, 07:44 AM
  2. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  3. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  4. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  5. Nested loop frustration
    By caroundw5h in forum C Programming
    Replies: 14
    Last Post: 03-15-2004, 09:45 PM