#include #include #include #include using namespace std; //Usually want to use the std namespace //declare our own namespace namespace test{ string msg1 = "!"; } //The message class that holds a string class Message{ //public members of Message public: Message(string); void printMsg(); private: string msg1; }; //Use Scope Resolution operator :: to show this is part of Message //Constructor Message::Message(string a){ this->msg1 = a; } //Just a display function void Message::printMsg(){ printf("Message: (%s)\n", this->msg1.c_str()); } //entry point int main(){ string input; string header("Hello World"); cout << header << " " << endl; //The << operator appends strings for printing list msgs; list::iterator msg_iter; while (cin >> input) { if (strcmp(input.c_str(), "done") == 0) { //strcmp looks like a c function... why? break; } Message * in_msg = new Message(input); msgs.push_back(in_msg); } for (msg_iter = msgs.begin(); msg_iter != msgs.end(); msg_iter++) { (*msg_iter)->printMsg(); //*msg_iter points to current message delete(*msg_iter); //no garbage collector, delete manually! } cout << test::msg1 << endl; //This msg1 is from the namespace test }