2

How to write some text into a txt file with MS-DOS encoding ? I'm using class FILE. May be I must use another class?

CString text;
 CString file_name;
 text = "My text must be in txt file in MS-DOS encoding.";
 file_name = "MyFile.txt";
 FILE *fp;
 fp = fopen(file_name, "w+");
 fprintf(fp, text + "\n");
 fclose(fp);
ArnoldRich
  • 21
  • 1
  • you set the locale, and thus the encoding, with the `imbue` method, http://stackoverflow.com/questions/11646368/how-to-set-file-encoding-format-to-utf8-in-c , but I'm not really sure about what is the right locale for MS-DOS, it's a quite old encoding and I don't have a Windows machine right now, but I assume that you can try something with this method. – user2485710 Dec 13 '13 at 04:58
  • 1
    "MS-DOS encoding" is not well-defined. At particular points in time, a reasonable guess could be codepage 437 or 850, but it depends on where you are. – tripleee Dec 13 '13 at 05:10

2 Answers2

0

There's nothing special about MS-DOS encoding other than end-of-line is represented by a \r\n two character sequence. If you open the file in text mode as you have done then this should happen automatically.

Mark Ransom
  • 299,747
  • 42
  • 398
  • 622
0

CharToOem (src, dst); must be used to transform into MS-DOS encoding.

ArnoldRich
  • 21
  • 1