to a File
This is a discussion on Howto Print
to a File within the C++ Programming
forums, part of the General Programming Boards category; I have a requirement to pad out some data in a binary file with the null charactor '
Howto Print \0 to a File
I have a requirement to pad out some data in a binary file with the null charactor '\0' added every second or thrid charactor. Try as I may I cannot prevent the app from ignoring the null charactor.
I have tryed various castings and conversions without any luck.
pseudo code below shows what I have right now.
string data = "J\0O\0H\0N\0";
file.open("c:\\somefile.dat", ios_base::binary | ios_base::in | ios_base::out);
file.write(data.c_str, sizeof data)
Only the first char 'J' makes it to the file followed by some junk equal to the sizeof data - the first char.
"put" will do what you want. However, as long as you give "write" the correct size, it should work also. Ie. Don't use "sizeof"
Last edited by _Elixia_; 12-15-2003 at 05:35 PM.
Boy that was a quick reply!
I have not tryed put yet but write does not work and I can see it writes J@somejunk to the destination file with a hex editor.
The constructor has no way of knowing that the string is longer than the first binary 0 unless you tell it.
file.open("c:\\somefile.dat", ios_base::binary | ios_base::in | ios_base:out);
file << data;
Popular pages Recent additions
By shu_fei86 in forum C# Programming
Last Post: 03-13-2009, 12:44 PM
By trevordunstan in forum C Programming
Last Post: 10-21-2008, 11:19 PM
By Abda92 in forum C Programming
Last Post: 05-22-2007, 01:19 PM
By year2038bug in forum Tech Board
Last Post: 09-05-2005, 03:30 PM
By laxmi in forum C Programming
Last Post: 05-10-2002, 04:10 PM