• Advertisement
Sign in to follow this  

ostream error

This topic is 4497 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Does anyone else notice that the smallest things to program most often become the biggest pains to compile? Anyway, I was trying to write a small log class for my new game (instead of using MessageBox() everywhere). Here is my code:
#include <fstream>
#include <string>


class CLog
{
public:
    CLog(std::string a_logfilename)
    {
        m_logfile.open(a_logfilename.c_str());
        AddString("");
        AddString("----- Start of Session -----");
    }
    
    ~CLog()
    {
        AddString("------ End of Session ------");
        AddString("");
    }
    
    void AddString(std::string a_str)
    {
        m_logfile << a_str << std::endl;
    }
    
private:
    std::ostream m_logfile;
};




My compiler gives me the following errors:
  • ostream 361 error: 'std::basic_ostream<CharT, _Traits>::basic_ostream() [with CharT = char, _Traits = std::char_traits<char>]' is protected
  • main.cpp 12 error: within this context
  • main.cpp 13 error: 'struct std::ostream' has no member named 'open'
  • I really don't know how to solve this, as an ostream normally has such a member... Anyone?

    Share this post


    Link to post
    Share on other sites
    Advertisement
    Quote:
    Original post by Kalasjniekof
    Thanks, it works now. I thought an ostream inherited from a fstream?


    No, or at least only privately. An ostream could also be the console; you don't get to construct them directly as a result (since there should only be cout to represent that).

    You might also consider aggregating a streambuf instead of a stream :\

    Share this post


    Link to post
    Share on other sites
    Sign in to follow this  

    • Advertisement