c++ - Substring Replace Vector -


this minimal code sample

i'm trying create array of substrings find can replace them single word. in case i'm changing common greetings simple 'hi'.

the problem when run code i'm getting error.

error: no matching function call 'std::vector >::push_back(const char [4], const char [4], const char [3])'

if me understand why error occurring , suggest solution perfect.

#include <iostream> #include <string> #include <algorithm> #include <cctype> #include <ctime> #include <vector>      vector<string> hiword;     hiword.push_back("hey", "sup", "yo");     (const auto& word : hiword){     while (true) {      index = r.find(word);      if (index == string::npos)         break;      r.replace(index, word.size(), "hi");   } } 

you might want start creating vector of strings want search , replace:

vector<string> searchwords = {"hey", "hello", "sup"}; 

then use loop run code wrote, e.g.

for (const auto& word : searchwords) {   while (true) {      index = r.find(word);      if (index == string::npos)         break;      r.replace(index, word.size(), "hi");   } } 

Comments

Popular posts from this blog

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -

javascript - Using jquery append to add option values into a select element not working -

javascript - Restarting Supervisor and effect on FlaskSocketIO -