July 6, 2007
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<<' in 'std::cout << str'
- 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.
- time_t t = time(NULL);
- void TServerFrame::tolog(const JString& str) {
- JString filename = getDir()+"log/rclog.txt";
- Can anyone help me?
- str = JString() + "Time: " + ctime(&t) + str + "\n";
- out << str; <——–and here
- if (out) {
- bool operator ==(const JString& str1, const char* str2);
friend bool operator ==(const char* str1, const JString& str2);
friend bool operator !=(const JString& str1, const JString& str2);
friend bool operator !=(const JString& str1, const char* str2);
friend bool operator !=(const char* str1, const JString& str2);
friend bool operator >(const JString& str1, const JString& str2);friend JString operator +(const JString& str1,const JString& str2);
friend JString operator +(const JString& str1,const char* str2);
friend JString operator +(const JString& str1,int value);
friend JString operator +(const JString& str1,char c);
};
ostream &operator <<(ostream &out, const JString& str2); <–this is the problem maybeThis is a large portion of the JString class
- }
- out.close();
- cout << str; <—– here
- #ifdef GC
class JString:public gc
#else
class JString
#endif
{
public:
unsigned char *buffer;
int len;JString();
JString(const JString& str);
JString(const char* text);
JString(int value);
JString(char c);
~JString() { clear(); len=0; stringc–; };void addbuffer(const char*, int lent);
void clear();
int length() const;
const char* text() const;
char charAt(int pos) const;
int indexOf(char check) const ;
int indexOf(const JString& str) const;
JString subJString(int begin) const;
JString subJString(int begin, int end) const;JString& operator =(const JString& str) { clear(); return operator <<(str); };
JString& operator <<(const JString& str);
JString& operator <<(const char* text);
JString& operator <<(int value);
JString& operator <<(char c);
unsigned char& operator [](int index);
unsigned char operator[](int index) const;friend bool operator ==(const JString& str1, const JString& str2);
friend - ofstream out(filename.text(),ios::out | ios::app);
- It happens on a few lines of code
- JString filename = getDir()+"errorlog.txt";
- out << "Time: " << ctime(&t);
- void TServerFrame::toerrorlog(JStri… str) {
- out << str << endl; <————here
Tags: linux web hosting, linux























