hi everyone..ok here's my problem

i have this program

#include <iostream>
#include <string>

using namespace std;
int main ()
{
string s1;
string s2;
string s3;
cout<<"Enter first string: ";
getline(cin, s1);

cout<<"Enter second string (to remove): ";
getline(cin, s2);


int indexhere = s1.find(s2); //the starting index (zero-based)
int numberofchars =s2.length(); //the number of characters to take away
if (indexhere!=-1)
s3= s1.erase(indexhere,numberofchars);
cout<<"Substring removed: "<<s3 <<'\n';
else
cout<<"Could'nt find input string in original string.\n";

}

it searches the second string inside the first one and deletes it..that works fine, but here's the problem:
i have to make it as a function with two string parameters and a return "string" value i.e if i call the function b=delString("abcdef","cde") then b should be b="abf"

like this

#include <iostream>
#include <string>

using namespace std;
char* delString(char s1, char s2)

{
    char s3;  
int indexhere = s1.find(s2); 
int numberofchars =s2.length(); 
if (indexhere!=-1)
s3= s1.erase(indexhere,numberofchars);
cout<<"Substring removed: "<<s3 <<'\n';
else
cout<<"Could'nt find input string in original string.\n";      

return s3;      
      }
int main ()
{
char b;
b=delString("abcdef","cde");
}

it doesn't work..
first it says " 'find' is not a type"
then it says " 'lenght' has not been declared", then
" 'erase' has not been declared" and so on...

can anyone please help me make this function work

>>char* delString(char s1, char s2)
those two parameters are wrong. They should be std::string, not char (which is just a single character)

This article has been dead for over six months. Start a new discussion instead.