Please excuse my ignorance.. i know a fair bit but am somehow still hazy on basics!?!Could you consider this simple example and tell me the best way to pass logmessages to ‘writeLogFile’?
void writeLogFile (ofstream *logStream_ptr)
{
FILE* file;
errno_t err;
//will check this and put in an if statement later..
err = fopen_s(&file, logFileName, "w+" );
//MAIN PROB:how can I write the data passed to this function into a file??
fwrite(logStream_ptr, sizeof(char), sizeof(logStream_ptr), file);
fclose(file);
}
int _tmain(int argc, _TCHAR* argv[])
{
logStream <<"someText";
writeLogFile(&logStream); //this is not correct, but I'm not sure how to fix it
return 0;
}
Instead of an
ofstreamyou need to use aFILEtype.Where elsewhere
Or you can use ofstreams only.
Where elsewhere
Based on comment below what you seem to want to do is something like:
Note that you really need more error checking than I have here, as you are dealing with c-style strings and raw pointers (both to the chars and the FILE).