The main function is what was given to me, and I attempted to write the rest. It's pretty basic, but I'm having trouble with the gettweet part.
How can I compare string subject to the subject inside messages[i]? Or am I doing this totally wrong?Code:#include <iostream> #include <vector> using namespace std; class Tweet { public: Tweet(); Tweet(string subject, string message); string getsubject(); string getmessage(); void addtext(string x); private: string subject; string message; }; Tweet::Tweet() { } Tweet::Tweet(string subject, string message) { this->subject=subject; this->message=message; } string Tweet::getsubject() { return subject; } string Tweet::getmessage() { return message; } void Tweet::addtext(string x) { message += x; } class Twitter { public: Twitter(); void addtweet(Tweet newmessage); Tweet gettweet(string subject); private: vector<Tweet> messages; }; Twitter::Twitter() { } void Twitter::addtweet(Tweet newmessage) { this->messages.push_back(newmessage); } Tweet Twitter::gettweet(string subject) { for(int i=0;i<=messages.size();i++) { if(subject == messages[i].subject) { return messages[i]; } } } int main() { string sub="Baseball"; string mess="Red Sox look good."; Tweet t(sub,mess); t.addtext(" - Real Good."); Twitter tw(); tw.addtweet(t); Tweet t2=tw.gettweet("Baseball"); cout << t2.getsubject << endl; cout << t2.getmessage << endl; }