You are not logged in.
How can I write output to a file in binary format instead of ascii?
Or... if I am using a buffer.. to write a buffer to binary format instead of ascii?
I am writing a lot of data to a text file and I would like to reduce the size by writing it all into a binary file instead of ascii?
Last edited by kdar (2012-12-13 14:36:41)
Offline
Basic I/O?
char buffer[100];
// C++ style
ofstream file;
file.open ("data.bin", ios::out | ios::binary);
file.write(buffer, sizeof buffer);
/* C style */
FILE* file2 = fopen("data2.bin", "wb");
fwrite(buffer, sizeof buffer, 1, file2);
A lot of people prefer the old C style functions for binary i/o even in C++ (and iostream for formatted i/o). Writing and readong more complex structures requires some castin, in C++ usually done with reinterpret_cast<char*>(someStructure).
Offline
Strange... doing C++ style returns me "error: 'flowC' does not name a type'.
What is this about?
Also.. Do you know how to write the buffer only when its full? I saw somewhere I can use something like this...
char buffer[2048];
flowC.rdbuff()->pubsetbuf(buffer, 2048);
.......
flowC << ValOne <<< ", " << ValTwo << endl;
Last edited by kdar (2012-12-13 17:16:59)
Offline
Is flowC decalred in a different namespace?
Offline
Strange... doing C++ style returns me "error: 'flowC' does not name a type'.
What is this about?
This sounds like a simple problem, but you're not providing enough information. Write up a complete but minimal code example that illustrates the problem you're talking about, and post it here.
Offline