0

write a program to replace each blank space with '#'

31st Aug 2016, 4:48 AM
padmesh
padmesh - avatar
2 Antworten
0
Oh yeah
31st Aug 2016, 9:57 AM
Nitish Arora
Nitish Arora - avatar
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);
31st Aug 2016, 12:07 PM
Cohen Creber
Cohen Creber - avatar