#include <iostream>
#include <string>
#include <iomanip>
usingnamespace std;
int main ()
{
int count;
int length;
int len;
char k;
string string;
string str;
bool done;
done=false;
cout<<"Enter a string: ";
cin>>string;
cout<<"Enter substring to remove: ";
cin>>str;
length=string.length();
len=str.length();
while (!done)
{
if (string.find(str)<=length && string.find(str)>=0)
{
done=true;
}
else
{
cout<<"The substring "<<str<<" could not be found.";
cout<<"\n";
cout<<"Press any character to terminate...";
cout<<"\n";
cin>>k;
return 0;
}
}
int a;
a=string.find(str);
string.erase(a,len);
cout<<"Press any character to continue...";
cout<<"\n";
cin>>k;
return 0;
}
Technically, you can do that. If you had switched the order of lines 12 and 13, it would've compiled fine. But once you've brought into scope an identifier or type that is the same as one in a broader scope, the one in the broader scope is hidden.
It's good practice to avoid doing so. (This may also serve as a compelling argument to use qualified identifiers such as std::string.)
It could. But honestly, the standard library string is so widely used, if I caught any of the coders I work with using the name 'string' to mean anything but the std::string, I'd tie 'em to a cactus in the desert and let the crows eat their eyes out.