Created
June 16, 2020 10:28
-
-
Save AhnMo/3c2d8215f701ff80eb5834eaaf3d0327 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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