I can't get the code sample to compile without further tricks. The compiler points out that you need a special code page for the special (chinese?) character.
string nameFile = "A_Unicode天file.txt";
In a current Windows one should use UNICODE anyway, so that it interprets all characters correctly if possible world-wide. If you use wstring instead of string under C++ this would already help. The strange current file name can be processed without problems and the file is created correctly under Win10. Which Windows version you use probably doesn't matter for this problem as long as UNICODE is supported. For access to hardware, however, a suitable driver would be necessary.
I suggest to change all needet texts to UNICODE to solve this Task.
wstring nameFile = TEXT("A_Unicode天file.txt");
ofstream out;
out.open(nameFile.c_str(), ios::out);
//EDIT1:
Although this is how it worked for me, it might make sense to use wfstream or wofstream instead of ofstream.
//EDIT2:
Codeblocks 17.12 uses TDM-GCC v5.1.0 (see info on their site)
I have tested the TDM-GCC-64 under Windows 10. The version results:
g++ -v
gcc version 9.2.0 (tdm64-1)
Without the UNICODE defines:
#define _UNICODE
#define UNICODE
I got several errors compiling with "g++ -std=c++03 demo.cpp -o demo"
After UNICODE was defined the TEXT() macro worked and the program could be compiled and created the desired file.
Using wfstream or wofstream brings additional problems with gcc:
58 | out.write(M23.c_str(), M23.length());
| ~~~~~~~~~^~
| |
| const char*
By definition, write expects this:
basic_ostream& std::basic_ostream::write (const char_type* s, streamsize n);
Instead of write it would be better to write the output as a stream:
wstring M23(TEXT("Hello World 101010100011101010010101010011010100101101010101\n\n\n\nQWERTYUIOP"));
wstring nameFile(TEXT("A_Unicode天file.txt"));
wfstream out;
out.open(nameFile.c_str(), ios::out);
out << M23.c_str() << "\n";
out.close();
-----------
If your compiler can't handle UNICODE, you might have to use a window specific solution with system calls. I would avoid this and rather use compilers which support UNICODE.
Install CodeBlocks with TDM-GCC or download the TDM-GCC here:
https://sourceforge.net/projects/tdm-gcc/
https://sourceforge.net/projects/tdm-gcc/files/TDM-GCC%20Installer/
----------
I also found this comment:
"ofstream is not very cooperative (refuses to take wstring parameters), and wofstream supposedly needs to know locale and encoding settings."
https://stackoverflow.com/questions/4053918/how-to-portably-write-stdwstring-to-file