Skip to content

Instantly share code, notes, and snippets.

@AhnMo
Created June 16, 2020 10:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AhnMo/3c2d8215f701ff80eb5834eaaf3d0327 to your computer and use it in GitHub Desktop.
Save AhnMo/3c2d8215f701ff80eb5834eaaf3d0327 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <map>
#include <vector>
#include <string>
#include <algorithm>
void findAtFirstAndChangeSecond(
std::vector<std::pair<std::string, std::string>>& v,
const std::string key,
const std::string val
) {
auto it = std::find_if(v.begin(), v.end(),
[&key](const std::pair<std::string, std::string>& p)
{ return p.first == key; });
if (it != v.end()) { it->second = val; }
}
int main(int argc, char *argv[]) {
std::vector<std::pair<std::string, std::string>> properties;
properties.emplace_back("ro.board.test", "1");
properties.emplace_back("ro.foo", "bar");
properties.emplace_back("ro.debuggable", "1");
properties.emplace_back("ro.gogo", "0");
properties.emplace_back("ro.dededede", "f00d");
properties.emplace_back("ro.dead", "beef");
//findAtFirstAndChangeSecond(properties, "ro.debuggable", "0");
for (const auto& [name, value] : properties) {
std::cout << "[" << name << "]: [" << value << "]" << std::endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment