PDA

View Full Version : چگونه از u16string در c++ استفاده کنیم؟



علی بهمنی جلالی
یک شنبه 07 شهریور 1395, 13:05 عصر
سلام
چطوری میشه از u16string که در c++11 معرفی شده استفاده کرد؟
با سپاس.

علی بهمنی جلالی
یک شنبه 07 شهریور 1395, 13:08 عصر
سلام
من توانستم به صورت زیر، در خط فرمان mlterm لینوکس، این نویسه و رشته‌ها را چاپ کنم.
#include <iostream>
#include <codecvt>
#include <locale>
#include <string>
using namespace std;

int main()
{
char16_t ch16 = u'ی';

wstring_convert< codecvt_utf8_utf16< char16_t >, char16_t > convert;
string a = convert.to_bytes( u"This string has UTF-16 content" );
u16string b = convert.from_bytes( u8"امتحان" );
u16string c = u"UTF-16";

cout << a << endl;
cout << b.size() << endl;
cout << convert.to_bytes( b ) << endl << convert.to_bytes( c ) << endl
<< convert.to_bytes( ch16 ) << endl;
}
برای چاپ این نویسه‌ها(کاراکترها) و رشته‌ها، از لینک زیر هم کمک گرفتم.

http://stackoverflow.com/questions/7232710/convert-between-string-u16string-u32string

142244

142245