1 R Jemma Harry What were you thinking? Harry, You seriously need to stop claiming your paperclip orders under the heading art supplies. Jemma EOF 2 R Jemma Jason I really really want to talk to you about those expense claims! Subject says it all... Jemma EOF |
#include <iostream> #include <fstream> #include <string> #include <vector> using namespace std; // this is the class that I want to use to create instances of the messages class Message { public: Message(); // default constructor void printMessage() const; // this prints it out so I can see if it works private: int messageNum; string status; string sender; string recipient; string subject; string messageBody; }; Message::Message() // default constructor { ifstream fin; // declares fin to ifstream fin.open("mail.txt"); // opens the text file fin >> messageNum; // takes in the first char for message number getline(fin, status); // takes in status R for read or N for new getline(fin, sender); // sender getline(fin, recipient); // recipient getline(fin, subject); // subject while (message != "EOF") // this will read in the message body until it sees EOF which means it is end of message body { messageBody.append(message); // puts the various lines in message body together if (messageBody != "") { messageBody.append("\n"); // adds the hard returns } getline(fin, message); // gets the next line } } void Message::printMessage() const // this member function just prints out all the info collected { cout << messageNum << " " << status << endl << sender << endl << recipient << endl << subject << endl << messageBody; } int main() { Message abc; // creates instance Message cde; // another instance vector<Message> systemMessages; // creates vector systemMessages.push_back(abc); // appends first instance systemMessages.push_back(cde); // appends second instance systemMessages[0].printMessage(); // calls member function systemMessages[1].printMessage(); // calls member function for other } |
|
|