1

I have a simple logger class which I tried to turn into accepting and outputting wstrings instead strings.

header:

#include <fstream>
using namespace std;

class CLog 
{
  public:
    CLog(wstring filename);
    ~CLog();
    void WriteString(string uString);
  private:
    fstream m_stream;
};

cpp:

#include "stdafx.h";
#include "log.h";

CLog::CLog(wstring uPath) 
{
  m_stream.open(uPath);
}
void CLog::WriteString(string uString)
{
  m_stream << uString.c_str() << endl;
}
CLog::~CLog()
{
  m_stream.close();
}

Can anybody suggest what I should use instead of fstream? I tried using wstringstream, but it did not even have .open to output it to file, so I thought that is the wrong approach.

I would like to keep the behaviour that it immediately writes to a file.

tmighty
  • 10,734
  • 21
  • 104
  • 218
  • 1
    look here http://stackoverflow.com/questions/1509277/why-does-wide-file-stream-in-c-narrow-written-data-by-default – kassak Apr 05 '13 at 09:16
  • The link that you posted is informative, but not something that helps. – tmighty Apr 05 '13 at 09:26
  • there was the thing you could use - `std::wofstream` – kassak Apr 05 '13 at 09:32
  • Wrong, this is the old version of my code that I posted. I thought I was clear on what I want by stating that it should accept wstring, perhaps I should have been even more clear on that. – tmighty Apr 05 '13 at 09:35

1 Answers1

4

I use "wofstream" instead of "fstream" now, and it works perfectly.

tmighty
  • 10,734
  • 21
  • 104
  • 218