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

This commit is contained in:
2024-02-29 20:44:33 -06:00
parent 047ff602ed
commit c2c095dfa7

View File

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