-
-
Save anonymous/145e2c524aa7a9bdc9f6 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 <vector> | |
#include <utility> | |
#include <string> | |
#include <sstream> | |
std::vector<std::pair<std::string, std::string> > | |
parse_data (std::string const& data) | |
{ | |
std::vector<std::pair<std::string,std::string> > values; | |
std::istringstream iss (data); | |
std::string line; | |
std::string key, value; | |
while (std::getline (iss, line)) { | |
std::istringstream inner_iss (line); | |
if (std::getline (inner_iss, key, '=') && std::getline (inner_iss, value)) { | |
values.push_back (std::make_pair (key, value)); | |
} | |
} | |
return values; | |
} | |
int | |
main (int argc, char *argv[]) | |
{ | |
typedef std::pair<std::string,std::string> StrPair; | |
std::vector<StrPair> values = parse_data ( | |
"hello=world" "\n" | |
"foo=bar" "\n" | |
); | |
for (std::vector<StrPair>::iterator it = values.begin (); it != values.end (); ++it) { | |
std::cerr << it->first << " = " << it->second << std::endl; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment