plz guide me i m having some error at line 28

#include <iostream>
using namespace std;

class str
{
  char s[30];
    public:
           str()
           {
                   strcpy(s,"");
                   }
     string getstring()
          {
             cout<<"enter the sting:";
             cin>>s;
           return s;  
                        }
     void displaystring()
     {
           cout <<"the string is:"<<s<<endl;
           }

                   
                          
                         string operator+= (string &t)
                             {
                                    
                                    strcat(s,s.t);
                                    
                                    return s;
                                    }
                                    };
                                    
                                    
           main()
          {
                     str string1;
                     str string2;
                     string1.getstring();
                     string2.getstring();
                      string1+=string2;
                     string1.displaystring();
                             

}

plz guide me i m having some error at line 28

After 48 posts you can't give us a better explanation than "some error." Since you think we're as psychic as you, read my mind for your error. :icon_rolleyes:

You have not defined the += function correctly. My guess is that you probably heard someone say "it must return a string" but they meant "str" object.

I got your example to work by fixing that up. I recommend you browse the Internet for how to correctly use operator+=.

Lastly, the actual error message you are seeing is due to the referring to a component that does not exist. I think you intended to use t.s ...but again t has to be a str object not a "string" for that to work.

plz guide me i m having some error at line 28

1. Explain your problem more clearly. Saying "plz guide me" is not very helpful for us, and it's ridiculously presumptuous that we will respond with thorough help when you can't type more than one sentence.
2. Post the error that you are getting. We aren't psychics that just know what your compiler is saying.
3. Think about what you are trying to do. On line 28, you have a serious confusion that is pretty inexcusable. In particular, s is a char array member of this class. There is no ".t" member of a character array. You probably mean "t.s". If you actually thought about what you were typing, and had a better naming convention, you would probably have caught this as you wrote it.
4. Clean up your code before you post it. The indentations and extra blank lines are infuriating. I truly hope your code doesn't look like this in your IDE
5. Write better code. Your class is named str, but two of your functions (including the one on line 28) return a string. There is a string type in the standard template library, and I doubt you want your char array wrapper class to return a 3rd type of string representation. If you are studying computer science in school, you have a very long way to go. You should learn to write careful code first. Even ridiculously simple classes like these should be built with care. The kind of sloppiness and laziness I see here will grow into a terminal affliction when you try to create more complex projects.

commented: I agree !! +3
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.