how to use tostring method in c++
#include <iostream>
#include <string>
using namespace std;
class MyClass {
public:
string toString() {
return "This is an example toString method.";
}
};
int main() {
MyClass obj;
string str = obj.toString();
cout << str << endl;
return 0;
}