C++ classes and objekts | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

C++ classes and objekts

I don't understand why my Programm doesen't output. Can someone help, please! So i'm trying to set private attribute name with help from public objekts. And then i try to write it. But my Programm dosen't have any output. #include <iostream> #include <string> using namespace std; class A { public: void setName(string x){ name = x; } string writeName(){ return name; } private: string name; }; int main () { string x; cout << "Write a name: "; cin >> x; cout << endl; A call; call.setName(x); call.writeName(); cin.get(); cin.get(); }

29th Jul 2020, 8:25 PM
Eert Aniemit
Eert Aniemit - avatar
3 Answers
+ 2
You need to put cout<< call.writeName()
29th Jul 2020, 8:31 PM
Gabriel Ilie
Gabriel Ilie - avatar
+ 2
Just You are not displaying returned result... cout<<call.writeName();
29th Jul 2020, 8:31 PM
Jayakrishna 🇮🇳
+ 1
thank you very much!
29th Jul 2020, 8:33 PM
Eert Aniemit
Eert Aniemit - avatar