[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
[an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]![]() |
![]() |
![]() |
|||||||||||||||||||||||||
|
|||||||||||||||||||||||||||
![]() |
![]() |
![]() |
Hej, Jeg sidder og er ved at skrive et større projekt i C++, men er løbet ind i et problem :( Jeg har brug for at skrive til en fil inde fra en hjemmebrygget klasse, men får en række compiler-fejl når jeg forsøger at kompilere skidtet (se minimalt eksempel nederst). Starten på fejlmeddelelsen ser ud som følger, jeg har klippet en del af de foreslåede "kandidater" fra: g++ -ansi -pedantic -Wall -c -o test.o test.cpp test.cpp: In member function `void Log::printMessage(std::basic_string<char, std::char_traits<char>, std::allocator<char> >) const': test.cpp:25: no match for `const std::ofstream& << std::string&' operator /usr/include/c++/3.2.2/bits/ostream.tcc:55: candidates are: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>&(*)(std::basic_ostream<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>] [snip] Fejlen ligger tilsyneladende i linien "logfile << msg << endl;" - Nogen der ved hvad jeg gør galt? Mvh ./Brix Minimalt eksempel: #include <fstream> using namespace std; class Log { public: Log (void); ~Log (void); void printMessage (string msg) const; private: ofstream logfile; }; Log::Log (void) { logfile.open ("test.txt"); } Log::~Log (void) { logfile.close (); } void Log::printMessage (string msg) const { logfile << msg << endl; } int main (void) { Log test; test.printMessage ("Hello World"); } -- Henrik Brix Andersen <sslug@sslug>
![]() |
![]() |
![]() |
||||||||||||
|
||||||||||||||
![]() | ||||||||||||||
|
||||||||||||||
![]() |
![]() |
![]() |