gpt4 book ai didi

c - 如何用(可读的)UTF8 字符写入文件?

转载 作者:行者123 更新时间:2023-12-04 12:05:51 35 4
gpt4 key购买 nike

我读取了一个包含 utf8 字符的文件,如下所示:

FILE *FileIN,*FileOUT;
FileIN=fopen("filename","r");
char string[600];
WideChar C[600],S[100];
fgets(string,600,FileIN);
wcscpy(C,UTF8Decode(string).c_bstr()); // widechar copy

它可以完美读取(运行程序时显示在编辑框中):

Edit1->Text=C;

Result ===> "3021";"亜";"7";"ア アシア つ.ぐ T1 や つぎ つぐ"

问题是,当我想在文件上写这个时:

FileOUT=fopen("txt.txt","w");    
fwrite(Edit8->Text.c_str(),strlen(Edit8->Text.c_str()),1,FileOUT);

Result ===> "3021";"?";"7";"? ??? ?.? T1 ? ?? ??"

问题是,如何将结果(我在程序运行中看到的结果)写入文件?

我在CodeGear C++Builder上使用C语言

已解决感谢 Christoph 和 nobugz 的帮助

我改变了这一行

fwrite(Edit8->Text.c_str(),strlen(Edit8->Text.c_str()),1,FileOUT);

对于这个,它起作用了。谢谢

fwrite(UTF8Encode(Edit8->Text).c_str(),UTF8Encode(Edit8->Text).Length(),1,FileOUT);

最佳答案

我不知道这个框架,但是如果你在读取文件后使用UTF8Decode(),你不应该在写入之前使用UTF8Encode()吗?

关于c - 如何用(可读的)UTF8 字符写入文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/557414/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com