K
K
KOLAMBA972017-01-29 16:07:59
Programming
KOLAMBA97, 2017-01-29 16:07:59

How to understand the structure of a text file at the encoding level?

Good day
It is necessary to write a program that would translate a text file from MS-DOS CP866 encoding to Windows-1251 encoding.
Nowhere can I find information on how a text file is arranged at the encoding level and how to read encoded characters, there are only encoding tables.
I wrote a program with which I write the code of one character to a binary file, when I open this file in a text editor I don’t 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 I extract character codes from a text file?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Pozharsky, 2017-01-29
@alex4321

"Nowhere I can find information on how a text file is arranged at the encoding level and how to read encoded characters, there are only encoding tables."
But no way. Encoding in relation to a text file is an external entity.
But you can read the content byte by byte and apply encoding conversion to it.
"How can I extract character codes from a text file?"
Well, N read bytes will provide the code of 1 character for the N-byte encoding of the encoding.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question