Sunday, July 12, 2009

Why can't I compile this Linux C++ code?

I've almost fixed all of the outdated code in an old Linux program coded in C++. However I keep getting the following error when I try to compile it.


no match for 'operator%26lt;%26lt;' in 'std::cout %26lt;%26lt; str'





It happens on a few lines of code





void TServerFrame::tolog(const JString%26amp; str) {


JString filename = getDir()+"log/rclog.txt";


ofstream out(filename.text(),ios::out | ios::app);


if (out) {


time_t t = time(NULL);


out %26lt;%26lt; "Time: " %26lt;%26lt; ctime(%26amp;t);


out %26lt;%26lt; str %26lt;%26lt; endl; %26lt;------------here


out.close();


}


}





void TServerFrame::toerrorlog(JString str) {


time_t t = time(NULL);


str = JString() + "Time: " + ctime(%26amp;t) + str + "\n";


cout %26lt;%26lt; str; %26lt;----- here





JString filename = getDir()+"errorlog.txt";


ofstream out(filename.text(),ios::out | ios::app);


if (out) {


out %26lt;%26lt; str; %26lt;--------and here


out.close();


}


}





Can anyone help me?

Why can't I compile this Linux C++ code?
The problem is that cout and cin don't know squat about Jstrings.





Does Jstring have a member function that returns, say, a c++ "string" type?


Or a member function that returns a normal, null-terminated c-type string?





Does Jstring have a member func. like c_str() (similar to the STL string type)?





This is where your problem lies.


No comments:

Post a Comment