#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 :)

This question has already been answered. Start a new discussion instead.