c++ wstring为file而不是string
C++ wstring to file instead of string
我有一个简单的记录器类,我试图将其转换为接受和输出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",它工作得很好。
相关文章:
- Seg Fault Issue C++ (file IO / getline)
- cppcheck在const std::string[]上引发警告
- 将std::string传递给WriteConsole API
- 为std::string的某个索引赋值
- std中有类似find_last_of的函数,而string中没有
- 使用 std::string () const 函数启动线程或未来
- 应用程序崩溃并显示"symbol _ZdlPvm, version Qt_5 not defined in file libQt5Core.so.5 with link time reference"
- 使用char类型将decimal转换为string,将string转换为decimal
- 迭代和比较映射<字符串、矢量<string>> c++ 中的值
- 当我们进行一些操作时,应该使用什么'std::string'或'std::stringstream'?
- 将向量解析<string>为字符串
- Android NDK clang 编译器错误在 Windows 上显示'No such file or directory'
- 'string.assign(string.data(), 5)' 是明确定义的还是 UB?
- 如何更改大小(std::string)
- "string.h"在构建适用于iOS的qt应用程序中找不到消息
- C++:如何将 unix 时间的字符串转换为 *tm?(使用时间错误:"cannot convert 'String' to 'tm*' ")
- std::string 的对象真的可以移动吗?
- 键入 'File' 以键入 'std::string'
- C++ " I want to add a new string at the end of the file How Can I do it? please help"中的文件处理
- c++ wstring为file而不是string