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