About std::ostream constructor

Viewed 12307

I want to use std::ostream like this:

int main()
{
    std::ostream os;
    os << "something ..." << std::endl;
    return 0;
}

There's an error said that the ostream constructor is protected:

error: ‘std::basic_ostream<_CharT, _Traits>::basic_ostream() [with _CharT = char; _Traits = std::char_traits]’ is protected.

But I remember operator<< could be overloaded like this:

// In a class. 
friend std::ostream & operator<<(std::ostream& out, const String & s) {
    out << s.m_s;
    return out;
}

Any advice on why my code doesn't work?

1 Answers
Related