I have two strings
Input
string a="101";
string b="(_^_)v_";
Output
string c="(1^0)v1";
Can you guys please tell me the way to solve it in C++?
I have two strings
Input
string a="101";
string b="(_^_)v_";
Output
string c="(1^0)v1";
Can you guys please tell me the way to solve it in C++?
For example, so:
#include <iostream>
#include <string>
int main ()
{
std::string a="101";
std::string b="(_^_)v_";
for(char& c: a)
b.replace(b.find("_"), sizeof("_") - 1, std::string(1, c));
std::cout << b;
}
(1^0)v1
Update: O(n) variant
#include <iostream>
#include <string>
int main()
{
std::string a="101";
std::string b="(_^_)v_";
for(std::string::iterator ia = a.begin(), ib = b.begin(); ia != a.end() && ib != b.end(); ++ib) {
if (*ib == '_') {
*ib = *ia;
ia++;
}
}
std::cout << b;
}