Okay, I'm making identical programs in C++ and Java (just in terms of doing the same thing) and I'm making an encryption program. My Java one is almost done and I've just started the C++ one. Is there a way to check for certain letters in a string and then replace them in C++? I know there's a find function but it won't work the way I want it to. This is the set up for replacing a letter in a string in Java:
if (pdphrase.contains("a")) {
pdphrase = pdphrase.replaceAll("a", "P1");
}
I need to do the same thing but in C++ and I can't find the methods to do so. Am I missing them or are they just not there?
This is what I've done in C++ but I know it doesn't work.
Google is a marvellous thing. If you'd googled c++ string find and c++ string replace you'd have found two functions called, surprisingly, find and replace.
I used find and replace but replace won't work for what I want. With the replace method you have to specify the location in the string to change you can't just do pdphrase.replace("a", "Z2");. I need to have the program find all the instances of the letter and replace them without me putting in the exact location. I've already looked at both of those methods on this website and tried using them before using append.
I took out the size_t for the other times I need to check for different letters because its obviously declared at the start and this works perfectly! Thanks a ton!