Thread: Scope resolution

  1. #1
    Registered User
    Join Date
    Mar 2016
    Posts
    12

    Scope resolution

    I've just started to study C++ and I have a question about scope resolution.

    In the following code fragment, why do I have to use "ios_base" in the setf(). Is "showpos" not included in the "std" namespace?

    Code:
    #include <iostream>
    using namespace std;
    
    
    int main(void)
    {
     cout.setf(ios_base::showpos);
     cout << 27 << endl;
    
    
     return 0;
    }

  2. #2
    Registered User
    Join Date
    Aug 2010
    Location
    Poland
    Posts
    733
    Quote Originally Posted by Attila View Post
    In the following code fragment, why do I have to use "ios_base" in the setf(). Is "showpos" not included in the "std" namespace?
    No, it is not (not directly). showpos is a member of the ios_base class. Without using namespace std, you would have to write:
    - std::cout instead of cout,
    - std::ios_base instead of ios_base,
    etc.

  3. #3
    Registered User
    Join Date
    Mar 2016
    Posts
    12
    Thanks a lot ... got it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. scope resolution operator (::)
    By Abhishek Pandey in forum C Programming
    Replies: 1
    Last Post: 04-02-2014, 01:33 PM
  2. Scope Resolution Operator Help?
    By shivam1992 in forum C++ Programming
    Replies: 11
    Last Post: 02-22-2013, 08:08 PM
  3. Scope resolution in C++
    By csonx_p in forum C++ Programming
    Replies: 6
    Last Post: 01-22-2009, 12:57 PM
  4. scope resolution operator ::: ??
    By Carlos in forum Windows Programming
    Replies: 7
    Last Post: 10-01-2002, 08:56 PM
  5. Replies: 4
    Last Post: 06-04-2002, 06:09 AM