[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]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

C++ ofstream problem



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>



 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 20:09 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *