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(); }
3 Answers
+ 2
You need to put cout<< call.writeName()
+ 2
Just You are not displaying returned result...
cout<<call.writeName();
+ 1
thank you very much!