Sign in to follow this  
Kalasjniekof

ostream error

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
    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

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now

    Sign in to follow this