1234567891011121314
#include "Message.h" #include <iostream> #include <string> using namespace std; int main() { Message msg(); msg.setMessage(); msg.getMessage(); return 0; }
123456789101112131415161718192021222324252627
#include <iostream> #include <string.h> class Message { public: Message(std::string initialMessage); ~Message(); std::string getMessage() { return message; } void setMessage(std::string message); private: std::string message; } Message::Message(std::string initialMessage) { setMessage(initialMessage); } Message::~Message() {} void Message::setMessage(std::string newMessage) { std::cout << "Please enter a message:\n"; std::cin >> newMessage; message = newMessage; }
Message msg();
Message msg;
void Message::setMessage(std::string newMessage)
messageObj.setMessage(myString);