Skip to content

Instantly share code, notes, and snippets.

@willeccles
Created October 13, 2016 03:00
Show Gist options
  • Save willeccles/8fcd3b3b0e0151807a943dca7ac84b29 to your computer and use it in GitHub Desktop.
Save willeccles/8fcd3b3b0e0151807a943dca7ac84b29 to your computer and use it in GitHub Desktop.
Replaces every vowel in given phrase(s) with "oodle"
// compile with:
// g++ oodle.cpp -o oodle -std=c++14
#include <iostream>
#include <string>
#include <regex>
#include <vector>
int main(int argc, char* argv[]) {
if (argc == 1) {
std::cout << "Usage: oddle [phrase ...]\n Replaces all vowels in given phrase(s) with 'oddle.'\n";
return 0;
}
std::vector<std::string> phrases;
std::string str;
for (int i = 1; i < argc; i++) {
str = std::string(argv[i]);
phrases.push_back(str);
}
std::regex v("[aeiou]", std::regex::icase|std::regex::optimize);
for (int i = 0; i < phrases.size(); i++) {
phrases[i] = std::regex_replace(phrases[i], v, "oodle");
}
for (auto s : phrases) {
std::cout << s << std::endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment