0
#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?

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by Mr_PoP
0

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.

0

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.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.