By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,384 Members | 927 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,384 IT Pros & Developers. It's quick & easy.

How do I fix the function string?

P: n/a
This is what I have so far:
Expand|Select|Wrap|Line Numbers
  1.  
  2. // This program changes 'the' to 'that'
  3. #include <iostream>
  4. #include <string>
  5. using namespace std;
  6.  
  7. // Function prototype
  8. void replaceSubstring(string1, string2, string3);
  9.  
  10. int main ()
  11. {
  12.    // Define three string objects.
  13.    string string1, string2, string3;
  14.  
  15.    // Assign values to all three.
  16.    string1 = "the dog jumped over the fence";
  17.    string2 = "the";
  18.    string3 = "that";
  19.  
  20.    return 0;
  21. }
  22.  
  23. //************************************************************
  24. // Definition of the replaceSubstring function. This function*
  25. // searches the strings for 'the'.                           *
  26. //************************************************************
  27.  
  28. void replaceSubstring(string1, string2, string3)
  29. {
  30.    string1.find('the');   // Find 'the'
  31.          string1.insert("that");
  32.    }
  33.  
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.
Nov 24 '10 #1
Share this Question
Share on Google+
3 Replies


Banfa
Expert Mod 5K+
P: 8,916
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.
Nov 24 '10 #2

100+
P: 542
There are aspects of the code posted that look uncommonly like VB
e.g. string1.find('the'); // Find 'the'
string1.insert("that");
Nov 25 '10 #3

Banfa
Expert Mod 5K+
P: 8,916
Your not up on your std::string C++ STL class, it has both of those methods :D
Nov 25 '10 #4

Post your reply

Sign in to post your reply or Sign up for a free account.