Thread: help with implementation

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    249

    Lightbulb help with implementation

    After I wort this program and it runs really good, :
    I got a question...
    How could I impement new subtraction operator in order to write this:

    string x = "Idontlikeprograming";
    string y = x - "dont";
    cout<< y; //the result is : " Ilikeprograming"

    So fare I wrote this program:

    ---------------------
    You can run it... I got the idea.. but I need to write it as shown up
    ---------------------
    #include <iostream>
    #include <string>

    string del1(string sor, string dis){
    string temp;
    string::iterator sor_ptr = sor.begin();
    while(sor_ptr <= sor.end()) {
    bool found = false;
    string::iterator dis_ptr = dis.begin();
    for(; dis_ptr<=dis.end(); dis_ptr++) {
    if (*sor_ptr == *dis_ptr){
    found = true;
    }// if
    }// for
    if (!found) temp+= *sor_ptr;
    sor_ptr++;
    }// While loop

    return temp;

    }// del1

    string operator - (string & left, string & right){
    // catenate two string values, forming a new string

    string res= del1( left, right);
    return res; // return result
    // we can also writ here the body of del1 function
    }


    int main(){
    /* string s1= " thisisnotfun";
    string s2= s1 - "not";
    cout<< s2<< endl; */
    string source;
    cout<< "Please inter the first string"<<endl;
    getline(cin, source);
    string dist;
    cout<< "Please inter the second string"<<endl;
    getline(cin,dist);
    string edit1 = del1(source, dist);
    cout << edit1 << endl;

    return 0;
    }

    Thankx Guys...
    Last edited by NANO; 04-29-2002 at 01:16 PM.
    C++
    The best

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. rand() implementation
    By habert79 in forum C Programming
    Replies: 4
    Last Post: 02-07-2009, 01:18 PM
  2. Replies: 1
    Last Post: 08-24-2008, 11:39 AM
  3. implementation file
    By bejiz in forum C++ Programming
    Replies: 5
    Last Post: 11-28-2005, 01:59 AM
  4. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  5. Pure virtual implementation, or not.
    By Eibro in forum C++ Programming
    Replies: 2
    Last Post: 03-19-2003, 08:05 PM