如何将CSV文件保存为UTF-8
How to save a CSV file as UTF-8
i编写代码来创建。CSV文件带有泰语字符。但是,当我使用该文件中的Microsoft Excel thai字符打开文件时,当我在记事本中打开它时,然后按保存。并再次在Excel中打开。我认为这是因为该程序未编码UTF-8。我必须做编程,将其保存为UTF-8。
std:: ofstream MyCSVFile;
MyCSVFile.open("myfile.csv", std::ios::out | std::ios::app);
MyCSVFile << "Name,Address" << endl;
MyCSVFile <<name<<","<<address << endl;
MyCSVFile.close();
}
您需要将BOM写入文件的开头。尝试以下操作:
const char *bom = "xefxbbxbf";
MyCSVFile << bom;
MyCSVFile << "Name...
这是一个很好的阅读:bom in wikipedia。
您需要执行以下操作(假设文件路径存储在FilePath
中):这是您应该使用的代码:
const std::wstring fileStr(FilePath);
wofstream mFile(FilePath);
mFile.imbue(std::locale(std::locale::empty(), new std::codecvt_utf8<wchar_t>));
if (mFile.is_open())
{
const wchar_t *bom = L"xefxbbxbf";
mFile << bom;
...
现在您可以写文本,当然可以关闭文件。
相关文章:
- HEX值到wchar_t字符(UTF-8)的转换
- 在全局变量中保存类的实例以重新创建类(创建"backup")
- 如何在选项卡视图Qt中设置一个新项目,并保存以前的项目
- 如何使用OpenCV将RBG图像转换为HSV,并将H、S和V值保存为C++中的3个独立图像
- 将字符指针十六进制转换为字符串并保存在文本文件C++中
- 在没有定义返回类型的函数中返回布尔值,并将结果保存在无错误的char编译中-为什么
- EvtExportLogneneneba API正在将远程计算机的事件日志保存到远程PC本身.如何将其保存到主机
- 在C++中将类(带有Vector成员)保存为二进制文件
- C++.我想将更改后的特定字符行保存在字符串中
- 使用FFMPEG将RGB图像序列保存到.mp4时出现问题
- 将RGB图像保存为PPM格式
- 带有Protobuf序列化的C++Hazelcast:字符串不是UTF-8格式的
- 转换特殊字符(UTF-8)
- 哈希文件递归并保存到矢量Cryptopp中
- 如何将二进制格式的 C++ 对象的 std::vector 保存到磁盘?
- 无法通过头文件保存变量的值
- 我们可以将数据永久保存为数据结构吗?
- 如何将CSV文件保存为UTF-8
- 如何将ASCII保存为C/ c++ (cpp)中的Unicode (UTF-16LE)
- 用unicode文件名保存文件的问题-如何以跨平台的方式正确保存UTF-8文件名