Added code to get a non-const char* from a std::string

master
Aadhavan Srinivasan 10 months ago
parent 047ff602ed
commit c2c095dfa7

@ -11,8 +11,10 @@ namespace connect_code {
/* Tokenizes a string, based on the given delimiter */ /* Tokenizes a string, based on the given delimiter */
std::vector<std::string> tokenize_str(std::string str, std::string delim) { std::vector<std::string> tokenize_str(std::string str, std::string delim) {
std::vector<std::string> result; std::vector<std::string> result;
char* c_str = str.data(); /* &str[0] is used to convert an std::string to a char*. I tried using string.data(),
char* c_delim = delim.data(); but that appears to return a const char*. */
char* c_str = &str[0];
char* c_delim = &delim[0];
char* tok = strtok(c_str, c_delim); char* tok = strtok(c_str, c_delim);
while (tok != NULL) { while (tok != NULL) {

Loading…
Cancel
Save