c++ wstring为file而不是string

C++ wstring to file instead of string

本文关键字:string file wstring c++      更新时间:2023-10-16

我有一个简单的记录器类,我试图将其转换为接受和输出wstring而不是字符串。

头:

#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();
}

谁能建议我应该用什么来代替fstream?我尝试使用wstringstream,但它甚至没有。open来输出到文件,所以我认为这是错误的方法。

我想保留它立即写入文件的行为

我现在用"wofstream"代替"fstream",它工作得很好。