+ 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; }
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"
+ 4
Thank you, you helped me a lot!
+ 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.
+ 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.
0
hola me pueden explicar como es que llamo una variable