Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. std::wcout can't print out Arabic chars and some mathmatical symbols

std::wcout can't print out Arabic chars and some mathmatical symbols

Scheduled Pinned Locked Moved C / C++ / MFC
helpiosquestionlounge
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    Falconapollo
    wrote on last edited by
    #1

    Recently I want to find a general solution for std::wcout so that it can print out all unicode strings. but, after poking around on google, i can't find useful. I'm stuck here, anybody can help me? _setmode(_fileno(stdout), _O_U16TEXT); won't work as expected. Here is my current code snippet:

                auto previousMode = \_setmode(\_fileno(stdout), \_O\_U16TEXT);
    	std::wifstream wifs;
    	wifs.imbue(std::locale(wifs.getloc(), new std::codecvt\_utf16));
    	wifs.open(L"F:\\\\重要网址.txt", std::ios\_base::binary);
    
    	std::wstring line;
    	std::getline(wifs, line);
    	
    	wcout << line << endl;
    	wifs.close();
    
    	wcout << endl;
    	cout << "∦" << endl;
    
    	std::wofstream wofs;
    	wofs.imbue(std::locale(wifs.getloc(), new std::codecvt\_utf16));
    	wofs.open(L"F:\\\\iMoney.txt", std::ios\_base::binary | std::ios\_base::ate);
    	wofs << line << endl;
    	wofs.close();
    	//it's important to restore mode to previous, otherwise std::cout will cause crash
    	\_setmode(\_fileno(stdout), previousMode);
    

    and here is some symbols to test your slution before post here: ∀, ∁, ∂, ∅, ∰, ∵, ∺, ⊙, ⋾, ⋻, ⋱, ⋭, ⋣, ⋧ Arabic: لطيفة الطقس اليوم

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups