Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8697431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:31:21+00:00 2026-06-13T01:31:21+00:00

I was using a stringstream recently stringstream ss (stringstream::in | stringstream::out); and I decided

  • 0

I was using a stringstream recently

stringstream ss (stringstream::in | stringstream::out);

and I decided to look at the declaration of in and out and I am somewhat confused with how they are declared. Would someone be able to clarify A. why they are written like this and B. how it works? I was expecting them to be written in standard enum syntax.

enum _Openmode
    {   // constants for file opening options
    _Openmask = 0xff};

static const _Openmode in = (_Openmode)0x01;
static const _Openmode out = (_Openmode)0x02;
static const _Openmode ate = (_Openmode)0x04;

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T01:31:22+00:00Added an answer on June 13, 2026 at 1:31 am

    The standard actually requires that those constants are variables, not just enumerators i.e. they have addresses in memory instead of just being a label for a constant. It doesn’t require that they are enums, they could be integers or bitsets instead. The spec requires:

    // 27.5.3.1.4 openmode
    typedef T3 openmode;
    static constexpr openmode app = unspecified ;
    static constexpr openmode ate = unspecified ;
    static constexpr openmode binary = unspecified ;
    static constexpr openmode in = unspecified ;
    static constexpr openmode out = unspecified ;
    static constexpr openmode trunc = unspecified ;
    

    So to meet this requirement the type is declared (in your standard library as an enumeration), then several variables of that type are declared, with the necessary values.

    An alternative implementation would be:

    enum _Openmode
        {   // constants for file opening options
        _In = 0x01,
        _Out = 0x02,
        _Ate = 0x04,
        _Openmask = 0xff};
    
    static const _Openmode in = _In;
    static const _Openmode out = _Out;
    static const _Openmode ate = _Ate;
    

    Which would look more like you expect, but there’s no advantage to doing it that way. If anything it’s worse, because it adds additional unused names (_In, _Out, _Ate etc.) to the namespace, preventing those same names being used elsewhere in the implementation and (very slightly) slowing down name lookup.

    The standard library is very often implemented in ways that seem unusual when compared to conventional application or library code. That’s needed to meet the exact requirements of a standard library, which must be usable in every possible situation and also avoid causing problems (such as name collisions or linker errors) with user code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to be able to serialize my C++ classes using standard techniques
Using the Redis info command, I am able to get all the stats of
i am using object of stringstream as follows: #include<iostream> #include <istream> using namespace std;
Hey so i'm using the pdCurses lib and stringStream to calculate and make a
I'm using JsonCpp to parse JSON in C++. e.g. Json::Reader r; std::stringstream ss; ss
I can open a program in terminal using: stringstream s; s<<./~/rajat/app -parameter; system(s.str().c_str()); My
Possible Duplicate: C++ Using stringstream after << as parameter I've a function like this
Solution: ShellAndWait(NULL, _FinalShellStrCmd, WAIT, 240, 1); Using stringstream to combine App and Arg into
We were using stringstream to prepare select queries in C++. But we were strongly
I'm using a stringstream to generate dynamically, the name of the files I need

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.