J
J. Campbell
I have an object with a member function that I'm using to generate a
stream of binary data that, rather than using, I want to output
directly to a file. It has a member function that returns an unsigned
long. Is there a standard C++ way to accomplish this without using
the ugly out.write(reinterpret_cast... line? Also, how can I use the
function return value directly in out.write, rather than having to go
through the temp variable?
Thanks,
Joe
#include <fstream>
using namespace std;
#include "worker.h"
int main(){
int data_in = 10;
unsigned long temp;
ofstream out("file.dat", ios:ut|ios::binary);
{
Worker Bob(data_in);
for (int i = 0; i < 100; ++i){
temp = Bob.get_data(); //returns unsigned long;
out.write(reinterpret_cast<char*>(&temp), sizeof(temp));
}
} //bob's day is done...have a nice weekend, bob
return 0;
}
stream of binary data that, rather than using, I want to output
directly to a file. It has a member function that returns an unsigned
long. Is there a standard C++ way to accomplish this without using
the ugly out.write(reinterpret_cast... line? Also, how can I use the
function return value directly in out.write, rather than having to go
through the temp variable?
Thanks,
Joe
#include <fstream>
using namespace std;
#include "worker.h"
int main(){
int data_in = 10;
unsigned long temp;
ofstream out("file.dat", ios:ut|ios::binary);
{
Worker Bob(data_in);
for (int i = 0; i < 100; ++i){
temp = Bob.get_data(); //returns unsigned long;
out.write(reinterpret_cast<char*>(&temp), sizeof(temp));
}
} //bob's day is done...have a nice weekend, bob
return 0;
}