c ++从文件中读取阿拉伯语文本

CSa*_*awy 6 c++ file-io text arabic

在C++中,我有一个包含阿拉伯文本的文本文件,如:

شكلكبتعرفتقرأعربيياابنالذين

我想将这个文件的每一行解析成一个字符串并在其上使用字符串函数(如substr,length,at ...等)然后将其中的一些部分打印到输出文件中.

我试过这样做,但它打印了一些垃圾字符,如"\'c7 \'e1 \'de \'d1 \"是否有支持阿拉伯字符的库?

编辑:只需添加代码:

#include <iostream>
#include <fstream>
using namespace std;
int main(){
  ifstream ip;
  ip.open("d.rtf");
  if(ip.is_open() != true){
    cout<<"open failed"<<endl;
    return 0;
  }
  string l;
  while(!ip.eof()){
    getline(ip, l);
    cout<<l<<endl;
  }

  return 0;
}
Run Code Online (Sandbox Code Playgroud)

注意:我仍然需要添加一些处理代码

if(l == "???? ???????"){
    string s = l.substr(0, 4);       
    cout<<s<<" is what you are looking for"<<endl;
 }
Run Code Online (Sandbox Code Playgroud)

vz0*_*vz0 2

您需要找出文件正在使用哪种文本编码。例如,要将 UTF-8 文件读取为 wchar_t,您可以 (C++11):

std::wifstream fin("text.txt");
fin.imbue(std::locale("en_US.UTF-8"));
std::wstring line;
std::getline(fin, line);
std::wcout << line << std::endl;
Run Code Online (Sandbox Code Playgroud)