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. outputting Δέλτα

outputting Δέλτα

Scheduled Pinned Locked Moved C / C++ / MFC
c++debugginghelpquestion
2 Posts 2 Posters 10 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.
  • M Offline
    M Offline
    mike7411
    wrote on last edited by
    #1

    I wrote the following code to output the Greek word "Δέλτα":

    #include
    #include
    #include
    using namespace std;

    int main() {
    _setmode(_fileno(stdout), _O_U16TEXT);
    cout << "\u0394\u03AD\u03BB\u03C4\u03B1" << endl;
    return 0;
    }

    For some reason, I get this error: --------------------------- Microsoft Visual C++ Runtime Library --------------------------- Debug Assertion Failed! Program: ...sers\Owner\source\repos\assert_test\x64\Debug\assert_test.exe File: minkernel\crts\ucrt\src\appcrt\lowio\write.cpp Line: 659 Expression: buffer_size % 2 == 0 For information on how your program can cause an assertion failure, see the Visual C++ documentation on asserts. (Press Retry to debug the application) --------------------------- Abort Retry Ignore --------------------------- Any ideas why the code is producing that error? Thank you.

    D 1 Reply Last reply
    0
    • M mike7411

      I wrote the following code to output the Greek word "Δέλτα":

      #include
      #include
      #include
      using namespace std;

      int main() {
      _setmode(_fileno(stdout), _O_U16TEXT);
      cout << "\u0394\u03AD\u03BB\u03C4\u03B1" << endl;
      return 0;
      }

      For some reason, I get this error: --------------------------- Microsoft Visual C++ Runtime Library --------------------------- Debug Assertion Failed! Program: ...sers\Owner\source\repos\assert_test\x64\Debug\assert_test.exe File: minkernel\crts\ucrt\src\appcrt\lowio\write.cpp Line: 659 Expression: buffer_size % 2 == 0 For information on how your program can cause an assertion failure, see the Visual C++ documentation on asserts. (Press Retry to debug the application) --------------------------- Abort Retry Ignore --------------------------- Any ideas why the code is producing that error? Thank you.

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      First things first, you're ignoring the return value of _setmode. If it's -1, the call failed, but you'll never know. Second, after reading the documentation on _setmode and associated error links, it appears you cannot use cout with the mode of stdout switched to Unicode. You have to use wprintf instead:

      #include
      #include
      #include

      using namespace std;

      int main()
      {
      int r;

      r =\_setmode(\_fileno(stdout), \_O\_U16TEXT);
      if (r == -1)
      	perror("Cannot set mode");
      
      wprintf(L"\\u0394\\u03AD\\u03BB\\u03C4\\u03B1\\n");
      
      return 0;
      

      }

      CORRECTION: You CAN use COUT, but you must use the wide version of it, but note the L in front of the string being output. It MUST be there:

      #include
      #include
      #include

      using namespace std;

      int main()
      {
      int r;

      r =\_setmode(\_fileno(stdout), \_O\_U16TEXT);
      if (r == -1)
      	perror("Cannot set mode");
      
      wcout << L"\\u0394\\u03AD\\u03BB\\u03C4\\u03B1" << endl;
      
      return 0;
      

      }

      Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles. Dave Kreskowiak

      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