0
write a program to replace each blank space with '#'
2 Antworten
0
Oh yeah
0
#include <iostream>
#include <string>
using namespace std;
int main()
{
int pos;
string str = "I really love cake";
while (pos != -1)
{
pos = -1;
pos = str.find(' ');
if(pos != -1)
str.replace(pos, 1, "#");
}
cout << "New string: " << str;
return 0;
}
This completely works, probably a more efficient way, but that's how I would have done it☺
If you want to have the user input their own string, just use:
getline(cin, str);