I’m not an expert on this but I have this code:
FILE *OUTPUT_FILE;
OUTPUT_FILE = fopen(file, "a+");
fprintf(OUTPUT_FILE, "%s", &keys );
fclose(OUTPUT_FILE);
And I would like to pass it to a fstream syntax
like
ofstream fs;
????
They are included on this function:
int Store(int keys, char *file)
I know this is a C function but since I’m learning C++ I would like to know how do I translate this to a C++
sorry I don’t know what else or if fs is compatible to fopen.
More information:
Thanks everybody but it seems its ignoring some values
int Store(int keys, char *file)
{
ofstream output_file("log.txt");
output_file << keys;
output_file.close();
cout << keys;
return 0;
}
when it oututs the file i just see a D i can see the hexadecimal values of the keys on the console but not being printed on the text….
First of all, ALL_CAPS should generally be reserved for macros — using it for a normal variable holding a
FILE *is generally a poor idea.As far as the rest goes, it would look something like this:
That could be a bit wrong, though — right now your function prototype says
keysis anint, but you’re passing it tofprintfusing the%sformat, which is for a string, not anint. As-is, the code produces undefined behavior, and it’s not completely certain what you really want. I’ve taken a guess I think is reasonable, but I’m not quite sure.Edit: In case you’re trying to write out the raw bytes of
keys, that would look something like:Thanks for the suggestion @ildjarn.