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.

  1. no match for 'operator<<' in 'std::cout << str'
  2. 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.

  3. time_t t = time(NULL);
  4. void TServerFrame::tolog(const JString& str) {
  5. JString filename = getDir()+"log/rclog.txt";
  6. Can anyone help me?
  7. str = JString() + "Time: " + ctime(&t) + str + "\n";
  8. out << str; <——–and here
  9. if (out) {
  10. 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 maybe

    This is a large portion of the JString class

  11. }
  12. out.close();
  13. cout << str; <—– here
  14. #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

  15. ofstream out(filename.text(),ios::out | ios::app);
  16. It happens on a few lines of code
  17. JString filename = getDir()+"errorlog.txt";
  18. out << "Time: " << ctime(&t);
  19. void TServerFrame::toerrorlog(JStri… str) {
  20. out << str << endl; <————here

Tags: ,

Tell a Friend Today!

del.icio.us Digg Furl Reddit Ask BlinkList blogmarks Blogg-Buzz Google Ma.gnolia Netscape ppnow Rojo Shadows Simpy Socializer Spurl StumbleUpon Tailrank Technorati Windows Live Wists Yahoo! Help

Permalink • Print

Track this entry

RSS BlogPulse

RSS Technorati Cosmos

Related Searches

, , , ,