#include <iostream>
#include <string>
using namespace std;
int main(void)
{
string test;
test="this is a test"
test.replace(' ','~')// replace the space with ~
cout << test;
return 0;
}
but it's not working can anyone help me?
#include <iostream>
#include <string>
using namespace std;
int main(void)
{
string test;
test="this is a test"
test.replace(' ','~')// replace the space with ~
cout << test;
return 0;
}
but it's not working can anyone help me?
If you're replacing every instance of a single character with another single character, std::replace from <algorithm> is better suited than any of the std::string::replace overloads:
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main(void)
{
string test;
test="this is a test";
replace(test.begin(), test.end(), ' ', '~');
cout << test <<'\n';
}
Your problem is trying to use an overload that doesn't exist.
If you're replacing every instance of a single character with another single character, std::replace from <algorithm> is better suited than any of the std::string::replace overloads:
#include <algorithm> #include <iostream> #include <string> using namespace std; int main(void) { string test; test="this is a test"; replace(test.begin(), test.end(), ' ', '~'); cout << test <<'\n'; }
Your problem is trying to use an overload that doesn't exist.
thnx alot :)
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.