0

hi all its me again, i just added a replace function but its throwing error C2661: 'std::basic_string<_Elem,_Traits,_Ax>::replace' : no overloaded function takes 2 arguments.

any idea?

#include <iostream>
#include <string>
using namespace std;

string padBlanks(string, int);
void removeLetter(string&, char);

int main()
{
string string1;
int padN;
string inStr;
char alpha;

cout<< "Please enter a string"<<endl;
cin>> string1;
cout<< "Please enter a number"<<endl;
cin >> padN;

padBlanks(string1, padN);

cout<< "Please enter a sentence"<<endl;
cin>> inStr;
cout<< "Please enter a char to be removed"<<endl;
cin >> alpha;

removeLetter(inStr, alpha);

cin.ignore();
cin.ignore();
}

string padBlanks(string string1, int padN)
{
string blank(padN,' ');

cout<< blank <<string1<<endl;
return blank;
}

void removeLetter(string& inStr, char alpha ) 
{  
int i;
	for(  i = 0; i < inStr.length(); i++)
	{
	if (inStr[i] == alpha)
		inStr.replace(i,alpha);	
	} 
	cout<< inStr <<endl;
}

did i go wrong in the logic or misunderstood the replace function?
thanks in advance for any advice

2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by Nick Evan
0

I think you misunderstood the use of the replace function. I could give you an explanation, but the C++ reference does it better then I could :) Look closely at the examples on the bottom of the page.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.