1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Help with Extractions

Discussion in 'C++' started by golf_girl32, Nov 23, 2010.

  1. golf_girl32

    golf_girl32 New Member

    Joined:
    Sep 28, 2010
    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    0
    I need help extracting words from a string. I'm not sure how to put it together. Here is my code...

    Code:
    #include<iostream>
    #include<string>
    using namespace std;
    class StringModify
    {
    public:
    void get_data();
    //takes a line of input from the user
    void extract_word();
    //extracts each word from the input line
    string reverse_word(const string& s);
    //returns a string which is reverse of s
    void swap(char& v1, char& v2);
    //interchanges value of v1 and v2
    void append(const string& reverse_word);
    //puts together each reversed word with whitespaces to get formatted_line
    void display();
    //displays both input line and formatted_line
    private:
    string line; //original string
    string formatted_line;//formatted string
    };
    
    int main()
    {
    StringModify data1;
    
    string get_data;
    
    cout<<"Enter the string: ";
    get_data(string line);
    cout<<"The original string is: "<<get_data<<endl;
    
    return 0;
    }
    void StringModify::get_data()
    {
    
    }
    void StringModify::extract_word()
    {
    
    }
    string StringModify::reverse_word(const string& s)
    {
        int start = 0;
        int end = s.length();
        string temp(s);
    
        while (start < end)
        {
            end--;
            swap(temp[start], temp [end]);
            start++;
        }
    
        return temp;
    }
    
    void StringModify::swap(char& v1, char& v2)
    {
        char temp = v1;
        v1 = v2;
        v2 = temp;
    }
    
     

Share This Page