write a program to replace each blank space with '#' | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
0

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

31st Aug 2016, 4:48 AM
padmesh
padmesh - avatar
2 ответов
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