Q:

What should binary file look like after conversion from text?

Problem:

Split the binary I/O from the example code into two: one program that converts an ordinary text file into binary and one program that reads binary and converts into text. Test these programs by comparing a text file with what you get by converting it to binary and back. 

Example code: 
#include "std_lib_facilities.h"

int main(){

    cout <<"Please enter input file name.\n";
    string name;
    cin >> name;
    // open file to read, with no byte interpretation 
    ifstream ifs(name.c_str(), ios_base::binary);
    if(!ifs) error("Can't open input file: ", name);

    cout << "Please enter output file name.\n";
    cin >> name;
    // open file to write 
    ofstream ofs(name.c_str(), ios_base::binary);
    if(!ofs) error("Can't open output file: ", name);

    vector<int> v;

    // read from binary file 
    int i;
    while(ifs.read(as_bytes(i), sizeof(int))) v.push_back(i);

    // do something with v

    // write to binary file
    for(int i = 0; i < v.size(); ++i) ofs.write(as_bytes(v[i]), sizeof(int));

    return 0;
}

Here is my code, instead of reading and writing int values, I tried with strings:
#include "std_lib_facilities.h"
void textToBinary(string, string);
//--------------------------------------------------------------------------------

int main(){

    const string info("This program converts text to binary files.\n");
    cout << info;

    const string testFile("test.txt");
    const string binaryFile("binary.bin"); 
    textToBinary(testFile, binaryFile);

    getchar();
    return 0;
}
//--------------------------------------------------------------------------------

void textToBinary(string ftest, string fbinary){
    // open text file to read
    ifstream ift(ftest);
    if(!ift) error("Can't open input file: ", ftest);

    // copy contents in vector
    vector<string>textFile;
    string line;
    while (getline(ift,line)) textFile.push_back(line);

    // open binary file to write
    ofstream fb(fbinary, ios::binary);
    if(!fb) error("Can't open output file: ", fbinary);

    // convert text to binary, by writing the vector contents
    for(size_t i = 0; i < textFile.size(); ++i){ fb.write(textFile[i].c_str(), textFile[i].length()); fb <<'\n';}

   cout << "Conversion done!\n";
}

Note:
My text file contains Lorem Ipsum, no digits or special punctuation. After I write the text using binary mode, there is a perfect character interpretation and the source text file looks exactly like the destination. (My attention goes to the fact that when using binary mode and the function write(as_bytes(), sizeof()), the content of the text file is translated perfectly and there are not mistakes.)
Question:
How should the binary file look like after I use binary mode(no char interpretation) and the function write(as_bytes(), sizeof()) when writing?  

A:

In both Unix-land and Windows a file is primarily just a sequence of bytes.
With the Windows NTFS file system (which is default) you can have more than one sequence of bytes in the same file, but there is always one main sequence which is the one that ordinary tools see. To ordinary tools every file appears as just a single sequence of bytes.
Text mode and binary mode in C++ concern whether the basic i/o machinery should translate to and from an external convention. In Unix-land there is no difference. In Windows text mode translates newlines from internal single byte C convention (namely ASCII linefeed, '\n'), to external double byte Windows convention (namely ASCII carriage return '\r' + linefeed '\n'), and vice versa. Also, on input in Windows, encountering a single byte value 26, a "control Z", is or can be interpreted as end of file.

Regarding the literal question,

” The question is in what format are they written in the binary file, shouldn't they be written in not-interpreted form, i.e raw bytes?

the text is written as raw bytes in both cases. The difference is only about how newlines are translated to the external convention for newlines. Since your text 1)doesn't contain any newlines, there's no difference. Edit: Not shown in your code except by scrolling it sideways, there's a fb <<'\n' that outputs a newline to the file opened in binary mode, and if this produces the same bytes as in the original text file, then there is no effective translation, which implies you're not doing this in Windows.

About the extra streams for Windows files, they're used e.g. for Windows (file) Explorer's custom file properties, and they're accessible e.g. via a bug in the Windows command interpreter, like this:

C:\my\forums\so\0306>echo This is the main stream >x.txt

C:\my\forums\so\0306>dir | find "x"
04-Jul-15  08:36 PM                26 x.txt

C:\my\forums\so\0306>echo This is a second byte stream, he he >x.txt:2nd

C:\my\forums\so\0306>dir | find "x"
04-Jul-15  08:37 PM                26 x.txt

C:\my\forums\so\0306>type x.txt
This is the main stream

C:\my\forums\so\0306>type x.txt:2nd
The filename, directory name, or volume label syntax is incorrect.

C:\my\forums\so\0306>find /v "" <x.txt:2nd
This is a second byte stream, he he

C:\my\forums\so\0306>_

I just couldn't resist posting an example. :)

1) You state that “My text file contains Lorem Ipsum, no digits or special punctuation”, which indicates no newlines.

