How can I write Persian text, for example "خلیج فارس", in a file using std::wfstream?I tried the following code but it does not work.
std::wfstream
#include <iostream> #include <string> #include <fstream> int main() { std::wfstream f("D:\\test.txt", std::ios::out); std::wstring s1(L"خلیج فارس"); f << s1.c_str(); f.close(); return 0; }
After starting the program, the file is empty.
You can use utf-8 C ++ 11 string literal and standard stream and string:
#include <iostream> #include <fstream> int main() { std::fstream f("D:\\test.txt", std::ios::out); std::string s1(u8"خلیج فارس"); f << s1; f.close(); return 0; }
First of all, you can leave
f << s1.c_str();
Just use
f << s1;
To write "خلیج فارس" with std::wstream, you must specify imbuefor the Persian language, for example:
std::wstream
imbue
f.imbue(std::locale("fa_IR"));
before writing to a file.
Source: https://habr.com/ru/post/1622645/More articles:React Native "Failed to connect to the development server." - androidWhy does the input field leave the div field after applying 100% width to it - htmlКак обновить объекты и компоненты GameplayKit в игре SceneKit - scenekitPHP threads (pthreads) work, but no Stackable class - multithreading'Stoi не был объявлен в этой области - c++How to put line breaks in Yii2 validation rule messages - phpCSS Overlay with pseudo-element - htmlPaste WinForms Form into Inno Setup Wizard - c #How to insert a form from a DLL into the Inno Setup Wizard page? - dllTesseract does not give recognition results (Android studio, Java) - javaAll Articles