請原諒我的無知。我知道一個公平一點,但我仍不知何故基礎上朦朧你能考慮這個簡單的例子,告訴我最好的方式傳遞到日誌消息「 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;
}
你混合stdio函數('fopen' /'fwrite' /等)和輸入輸出流。永遠不要這樣做!另外,如果'logStream_ptr'是一個指向打開文件流的指針,爲什麼要打開另一個文件? –
向我們顯示您的實際代碼。同時嘗試編輯您的問題,以便更清楚地詢問問題。你想要''writeLogFile'函數做什麼? – LihO