can anyone help me? how can we use endl in binary mode for files?
for expl.
fstream myfile;
myfile.open("test.txt",fstream::in|fstream::out|fstream::binary)
myfile<<"hi"<<endl<<"bye";
it won't go next line.....what should i do?
i wanted to write address book program ,in binary mode i could move in my file easier(i think)
but when i want to input my string in the file,it dose not accept .....
at that point if you want to continue in binary, you are well beyond my area of expertise.
With strings however you could use a variety of options such as MyString.rfind('\n',(character count))
and as for passing a string to a file, that too is only a few lines of code:
1 2 3 4 5 6 7 8 9 10 11
//untested code
#include <fstream>
#include <string>
ofstream myfile;
string mystring;
myfile.open("test.txt"); // include modifiers as needed
getline(cin, mystring); //presuming you're entering the person by name, will not include the '\n' character, will include spaces, not sure about dashes
myfile << mystring; // puts what you wrote into a file
myfile.close()
You cannot seek properly unless you are using binary file I/O.
But you don't get the convenient newline translation unless you are using textual file I/O.
There's a way to cheat, but it'll take me a short bit to figure it out.
For a not-so-great cheat, you could just use macros to check your OS and output the proper string that way.