+ 5

How to implement the autocomplete class to a variable without calling it from the class (like a string)?

For example, if you call string to the output stream(cout) or operator=+-, instead it will be placed *char is a pointer to the text contained in the string class, not the string class which calls are impossible. How to do the same with my class? string a="ssss"; s='s'+s+'f'; cout<<a;// output sssssf class A{ public: char c[5]; }; int main(){ /*** A a="ssss"; cout<<a; ***///instead A a; a.c="ssss"; cout<<a.c; }

29th Dec 2016, 2:08 PM
SUPER_S
SUPER_S - avatar
5 Answers
+ 4
You need to overload "<<". std::ostream& operator<<(std::ostream &cout, const A &a){ cout << a.c; return cout; } Then you can: A a; a.c = "ssss"; cout << a; // prints "ssss"
29th Dec 2016, 2:14 PM
Schindlabua
Schindlabua - avatar
+ 4
Thank you, you helped me a lot!
29th Dec 2016, 3:06 PM
SUPER_S
SUPER_S - avatar
+ 4
Facebook Intento De Ssesion si tienes alguna duda posteala en la secciĂłn de Q&A. Antes de postear por favor realiza una bĂșsqueda, quizĂĄs tu pregunta ya fue hecha anteriormente.
28th Jun 2018, 2:51 AM
Mickel
Mickel - avatar
+ 3
Same thing, different operator. You should probably create a new instance after adding though: A operator+(A const &a, char c){ return A(a.c + c); } You also need an overload with arguments swapped.
29th Dec 2016, 2:26 PM
Schindlabua
Schindlabua - avatar
0
hola me pueden explicar como es que llamo una variable
1st Apr 2018, 7:22 AM
Facebook Intento De Ssesion
Facebook Intento De Ssesion - avatar