How do I fix the function string?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • JSwizzle

    How do I fix the function string?

    This is what I have so far:
    Code:
    // This program changes 'the' to 'that'
    #include <iostream>
    #include <string>
    using namespace std;
    
    // Function prototype
    void replaceSubstring(string1, string2, string3);
    
    int main ()
    {
       // Define three string objects.
       string string1, string2, string3;
    
       // Assign values to all three.
       string1 = "the dog jumped over the fence";
       string2 = "the";
       string3 = "that";
    
       return 0;
    }
    
    //************************************************************
    // Definition of the replaceSubstring function. This function*
    // searches the strings for 'the'.                           *
    //************************************************************
    
    void replaceSubstring(string1, string2, string3)
    {
       string1.find('the');   // Find 'the'
             string1.insert("that");
       }
    I am trying to replace all instances of 'the' with 'that'. I know it should be fairly simple, but for some reason, I need some help.

    Also, do any of you experience peculiar program errors when running Microsoft Visual Basic? I've had to reinstall mine several times...

    Thanks in advance.
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    Start by declaring it correctly. The most basic text books or C++ tutorials should show examples of calling a function with parameters.

    You need to give the parameter type and optionally the parameter name.

    Comment

    • whodgson
      Contributor
      • Jan 2007
      • 542

      #3
      There are aspects of the code posted that look uncommonly like VB
      e.g. string1.find('t he'); // Find 'the'
      string1.insert( "that");

      Comment

      • Banfa
        Recognized Expert Expert
        • Feb 2006
        • 9067

        #4
        Your not up on your std::string C++ STL class, it has both of those methods :D

        Comment

        Working...