cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Visit the PTCooler (the community lounge) to get to know your fellow community members and check out some of Dale's Friday Humor posts! X

Read chinese string line by line from text in c or c++.

ndaslaniya
1-Newbie

Read chinese string line by line from text in c or c++.

Read chinese string line by line from text in c or c++.

I want to read chinese string from text file using c or c++.

But when i converted from wstring to string.it seems not correct.

Please find below code which i wrote.

_setmode(_fileno(stdout), _O_U16TEXT);

wifstream wifs;

wstring txtline;

//Open file

wifs.open("C:\\Users\\Public\\abc.txt");

// We are going to read an UTF-8 file

wifs.imbue(locale(wifs.getloc(), new codecvt_utf8<wchar_t, 0x10ffff, consume_header>()));

std::vector<std::string> vectTextLine;

//read line by line

while(getline(wifs, txtline))

{

wcout << txtline << L'\n';

//convert wstring to string

std::string s1 = WStringToString(txtline);

}

wifs.close();

std::string WStringToString(const std::wstring& s)

{

std::string temp(s.length(), ' ');

std::copy(s.begin(), s.end(), temp.begin());

return temp;

}

0 REPLIES 0
Top Tags