Well I've re-done the layout as to make it easier for me to follow and whatnot, I only have left to do the remove function, which I should be able to implement the same science as the previous example, as we are still able to directly manipulate our r.orig_line and r.del_line, right? Here is my code so far:
Code:
#include <iostream>
#include <string>
using namespace std;
/*************************************************************************************
Class: removed
Purpose: The user will input a line of text, at which time he will be asked
to remove a word from the phrase. We will then proceed to removing
the word.
Methods: remove: it will perform the same task as our previous remove function
istream &operator>> : we must overload the input stream so that we can handle
our removed (r) data type on the lhs
ostream &operator<< : we must overload the output stream also, so that we can
manipulate r as a rhs variable.
**************************************************************************************/
class removed{
private:
string orig_line; //our string before mod
string del_line; //our new string after it has been altered
public:
friend istream &operator>>(istream &is, removed &r); //overloaded input
friend ostream &operator<<(ostream &os, removed &r); //overloaded output
bool remove(string &s); //same as last example, we'll take a referenced string to manipulate with
};
//What the Input Stream will be doing
istream &operator>>(istream &is, removed&r){
cout << "Please enter a line of text:";
cout.flush();
getline(is, r.orig_line);
return is;
}
//What the Output Stream will be doing
ostream &operator<<(ostream &os, removed&r){
os << "The line: " << r.orig_line << endl;
os << "The new line: " << r.del_line << endl;
return os;
}
bool removed::remove(string &s){
/* the coding for the remove will go here*/
cout << "Removing " << s << " from " << orig_line << " " << endl;
}
/* Function main */
int main()
{
removed r;
string word;
cin >> r;
cout << "What word would you like to remove: ";
cout.flush();
cin >> word;
if (r.remove(word))
cout << r;
else
cout << "Error removing word " << word << endl;
return 0;
}
Also, I've noticed that a few of the members here (including yourself) color code their code, is this done by manual process or can you get a script for it?