I'm currently writing an image exporter in which i have to end the header with a "\n" before the raw data is written. The problem is that on win32 this equals to x00D x00A (that's hex value D followed by A). I need unix style, with only the hex A. I replaced the "\n" by one byte with value and still got the 2 bytes?????
here is some code:
#include <fstream>
using namespace std;
int main(int argc, char *argv[]) {
ofstream ofile("testing.txt"); // open testing file
char * onebyte; // unsigned so we can enter a number
onebyte=new char; // allocate ONE byte
onebyte[0]=10; // 10=x00A (unix style \n)
ofile.write(onebyte,1); // write ONE byte
ofile.close(); // close it
return 0; // the end
}
If you compile with gcc 2.95 or 3.2 and run it, a file with size 2 will be generated. Using HexEdit you can see that it's the D and then A. If i replace in the code the 10 by 11, then i get a file size one, only containing hex value B (which is 11 decimal).
How can i write one byte containing only x00A with the fstream????
stephan
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
nevermind, i found it.....
ofstream ofile("testing.txt",ofstream::binary);
does the trick. The meansing of binary here is the same as in ftp, that's what i learned after more than one hour tweaking :-(
stephan
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I'm currently writing an image exporter in which i have to end the header with a "\n" before the raw data is written. The problem is that on win32 this equals to x00D x00A (that's hex value D followed by A). I need unix style, with only the hex A. I replaced the "\n" by one byte with value and still got the 2 bytes?????
here is some code:
#include <fstream>
using namespace std;
int main(int argc, char *argv[]) {
ofstream ofile("testing.txt"); // open testing file
char * onebyte; // unsigned so we can enter a number
onebyte=new char; // allocate ONE byte
onebyte[0]=10; // 10=x00A (unix style \n)
ofile.write(onebyte,1); // write ONE byte
ofile.close(); // close it
return 0; // the end
}
If you compile with gcc 2.95 or 3.2 and run it, a file with size 2 will be generated. Using HexEdit you can see that it's the D and then A. If i replace in the code the 10 by 11, then i get a file size one, only containing hex value B (which is 11 decimal).
How can i write one byte containing only x00A with the fstream????
stephan
nevermind, i found it.....
ofstream ofile("testing.txt",ofstream::binary);
does the trick. The meansing of binary here is the same as in ftp, that's what i learned after more than one hour tweaking :-(
stephan