Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
Zitat von »"Schnitter"«
Gibts eigentlich einen guten Grund, nicht ofstream/ifstream sondern FILE zu benutzen?
Zitat von »"Deviloper"«
Ehm tjo ... FILE ist wohl ein überbleibsel aus C ... nja wenn man C++ programmiert, sollte man auch die entsprechenden Klassen dafür nehmen ...
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
void CLogfile::fTextout (int Color, bool List, const char *Text, ...) { TCHAR buffer[MAX_BUFFER]; // char-Buffer va_list pArgList; // Liste der übergebenen Argumente // String aus den Argumenten erstellen va_start (pArgList, Text); vsprintf ((char *) &buffer, Text, pArgList); va_end (pArgList); // Erzeugten String schreiben Textout (Color, List, (char *) &buffer); } // fTextout (farbig, Liste) |
Ehm ...Zitat
C-/C++-Quelltext
1 2 3 4 5 6 7 8 9 10 11 12 13 14 void CLogfile::fTextout (int Color, bool List, const char *Text, ...) { TCHAR buffer[MAX_BUFFER]; // char-Buffer va_list pArgList; // Liste der übergebenen Argumente // String aus den Argumenten erstellen va_start (pArgList, Text); vsprintf ((char *) &buffer, Text, pArgList); va_end (pArgList); // Erzeugten String schreiben Textout (Color, List, (char *) &buffer); } // fTextout (farbig, Liste)
Tja ... da ist dein ProblemZitat
Jetzt hätte ich aber doch noch ein paar Fragen:
Was ist also der Unterschied zwischen TCHAR und char?
C-/C++-Quelltext |
|
1 2 3 4 5 |
#if (_UNICODE) typedef TCHAR wchar_t; #else // !_UNICODE typedef TCHAR char; #endif // _UNICODE |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
void CLogfile::fTextout (int Color, bool List, const char *Text, ...) { char buffer[MAX_BUFFER]; // char-Buffer va_list pArgList; // Liste der übergebenen Argumente // String aus den Argumenten erstellen va_start (pArgList, Text); vsprintf (buffer, Text, pArgList); va_end (pArgList); // Erzeugten String schreiben Textout (Color, List, buffer); } |
C-/C++-Quelltext |
|
1 2 3 4 5 |
#if (_UNICODE) typedef TCHAR wchar_t; #else // !_UNICODE typedef TCHAR char; #endif // _UNICODE |
Zitat
... Du solltest wissen, dass (char *) &buffer einen char** in einen char* castet! Normal sollte es sogar drin sein die Funktion einmal const zu machen ...
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
class CLogfile : public TSingleton<CLogfile> { // Memberfunktionen public: CLogfile (); ~CLogfile (); void CreateLogfile (const char *LogName); void WriteTopic (const char *Topic, int size); void Textout (const char *Text); void Textout (int Color, const char *Text); void Textout (int Color, bool List, const char *Text); void fTextout (const char *Text, ...); void fTextout (int Color, const char *Text, ...); void fTextout (int Color, bool List, const char *Text, ...); void FunctionResult (const char *Name, bool Result); // Membervariablen private: FILE *m_Logfile; }; |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
#ifndef TSINGLETON #define TSINGLETON template <class T> class TSingleton { protected: // Membervariablen static T *m_pSingleton; // Statisches Objekt public: // Memberfunktionen // Destruktor // virtual ~TSingleton () { } // Get // // Aufgabe: Wenn nötig, statisches Objekt erzeugen und // Zeiger darauf zurückgeben // inline static T* Get () { // Existiert schon eine Instanz? if (!m_pSingleton) m_pSingleton = new T; // Nein, dann neue Instanz erzeugen // Zeiger auf die Instanz zurückgeben return (m_pSingleton); } // Get // Statisches Objekt freigeben // static void Del () { // Gab es eine Instanz? if (m_pSingleton) { delete (m_pSingleton); // Ja, dann freigeben m_pSingleton = NULL; // und Zeiger auf NULL setzen } } // Del }; // Die statische Variable erzeugen // template <class T> T* TSingleton<T>::m_pSingleton = 0; #endif |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
class Logfile : public TSingleton<Logfile> { public: Logfile() : m_pFile(NULL) {}; ~Logfile() { if (m_pFile != NULL) fclose(m_pFile); } public: enum color { LFC_BLUE = 0, LFC_GREEN, // ... }; public: void create(const char*); void write_topic(const TCHAR*, std::size_t); /* wofür ist hier size? */ void write_text(const TCHAR*); void write_text(color const&, const TCHAR*, bool list = false); /* int color machst du nen enum draus :) */ void write_text(const TCHAR*, ...); void write_text(color const&, const TCHAR*, ...); void write_text(color const&, bool list, const TCHAR*, ...); void write_result(const TCHAR*, bool); private: FILE* m_pFile; }; |
Werbeanzeige