How to understand structurc text file on the encoding level?

Good day
You need to write a program that would translate a text file from character encoding MS-DOS CP866 encoding Windows-1251.
I can't find information how to construct a text file at the level of coding and how to read encoded characters, there are only encoding.
Wrote program code where a single character is recorded in a binary file, when you open this file in a text editor do not get anything intelligible.
2c46c825893a44d48c25652be7bbb4ff.png

program code:

#include
#include
#include
#include
using namespace std;
int main(void)
{
int x=0, y=412;
ofstream out("1.bin",ios::binary|ios::out);
out.write((char*)&y,sizeof y);
out.close();
return 0;
}

How can you extract the character codes from a text file?
August 19th 19 at 23:07
1 answer
August 19th 19 at 23:09
"I can't find information how to construct a text file at the level of coding and how to read encoded characters, there are only encoding."
And in any way. Encoding relative to a text file - the essence of the external.
But you can read the content byte by byte and apply an encoding conversion.

"How can you extract the character codes from a text file?"
Well read N bytes and it will provide the code for 1 character N-byte character encoding encoding.
By the way, I don't understand why still nobody guessed to put in the text file info about its encoding. - Brady.Friesen30 commented on August 19th 19 at 23:12
: And where exactly this info is necessary to put?
It will also be part of the text file then. - Camylle.Sauer commented on August 19th 19 at 23:15
: well, the trigger will tag some stick and all, or at the OS level to require some metadataedit - Brady.Friesen30 commented on August 19th 19 at 23:18
: only this is a special kind of markup it turns out - with metadata. Not a text file. And there is already a lot. That to OS (by the way, here it is the filesystem, not the OS) - as for me - illogical at the OS level to share the test files and not binary (and for the latter, this attribute has no meaning). - Cordell.Schust commented on August 19th 19 at 23:21
, UTF-BOM is just such information. Is at the beginning of the text file if the file is in UTF. - devyn.Keebler commented on August 19th 19 at 23:24

Find more questions by tags Character encodingC++Programming