|
C-/C++-Quelltext
|
1
|
ostream& write ( const char* s , streamsize n );
|
Write block of data
Writes the block of data pointed by s, with a size of n characters, into the output buffer. The characters are written sequentially until n have been written.
This is an unformatted output function and what is written is not necessarily a c-string, therefore any null-character found in the array s is copied to the destination and does not end the writing process.
Es ist nicht schlau das Logbuch ständig zu öffnen (ostream) ohne zu schließen (close). Nur weil du die Methode write benutzt, bedeutet das nicht, dass in die Datei sogleich etwas hineingeschrieben wird.
Write füllt nur den Ausgabepuffer mit Daten!
Du musst den Stream schließen (
close()), oder die Methode
flush() aufrufen. Achso, und natürlich das
IOS::APP (für append, anhängen) benutzen
in etwa so:
|
C-/C++-Quelltext
|
1
2
3
4
5
6
7
8
9
10
|
void DLL WriteToLog(std::string pcFormat)
{
std::ofstream Log;
Log.open("Log.txt", std::ios::app);
Log.write(pcFormat.c_str(),pcFormat.size());
Log.close();
}
|
@TrikkieMikkie
c_str() ist doch ein objekt von string.
WTF? c_str() ist eine Methode der Klasse std::string. Diese Methode gibt dir einen mit 0 - terminierenden String. (Q2)
Q1:
http://www.willemer.de/informatik/cpp/fileop.htm
Q2:
http://www.cplusplus.com/reference/string/string/c_str/