0

What's the difference with following codes:

Code #1: Using Binary Mode

int main()
{
    std::fstream w("D:\\file.txt", std::ios::out | std::ios::binary);

    char *p = "Hello World\r\nHi";

    w.write(p, strlen(p));

    // Close the file
    w.close();
}

Code #2: Using Text Mode

int main()
{
    std::fstream w("D:\\file.txt", std::ios::out);

    char *p = "Hello World\r\nHi";

    w.write(p, strlen(p));

    // Close the file
    w.close();
}

Does it matter whether I use binary or text mode in case of writing strings like this?

user963241
  • 6,758
  • 19
  • 65
  • 93

1 Answers1

0

Basically, if you're working with text, bits represent text data, but in binary, bits represent custom data (not only text, but audio, image and etc). If you intend to work with text, I'd suggest you to use text mode, since it'll be less prone to get corrupted and easier to use with other applications.