انجمن‌های فارسی اوبونتو

کمک و پشتیبانی => برنامه‌سازی => نویسنده: علی ۵۰۰ در 02 شهریور 1395، 06:44 ب‌ظ

عنوان: چگونه از u16string در c++ استفاده کنیم؟
ارسال شده توسط: علی ۵۰۰ در 02 شهریور 1395، 06:44 ب‌ظ
سلام
چطوری میشه از u16string که در c++11 معرفی شده استفاده کرد؟
با سپاس.
عنوان: پاسخ : چگونه از u16string در c++ استفاده کنیم؟
ارسال شده توسط: علی ۵۰۰ در 07 شهریور 1395، 12:06 ب‌ظ
سلام
من توانستم به صورت زیر، در خط فرمان mlterm لینوکس، این نویسه و رشته‌ها را چاپ کنم. (خط فرمان 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

(http://forum.ubuntu.ir/index.php?action=dlattach;topic=138871.0;attach=44401;image)

(http://forum.ubuntu.ir/index.php?action=dlattach;topic=138871.0;attach=44411;image)