Skip to content

Instantly share code, notes, and snippets.

@javagg
Created September 13, 2012 12:29
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save javagg/3714006 to your computer and use it in GitHub Desktop.
Save javagg/3714006 to your computer and use it in GitHub Desktop.
transform vector<string> to char* array
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
int main() {
std::vector<std::string> symbols = {"IF1209", "IF1210"};
std::vector<const char *> chars(symbols.size());
std::for_each(symbols.begin(), symbols.end(), [](std::string& s) {
std::cout << s << std::endl;
});
std::transform(symbols.begin(), symbols.end(), chars.begin(), std::mem_fun_ref(&std::string::c_str));
std::for_each(chars.begin(), chars.end(), [](const char *s) {
std::cout << s << std::endl;
});
return 0;
}
@OnlyZero
Copy link

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment