From 0ff1220ca5d6ed0a8952405926179af08f4672d8 Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 29 Feb 2024 20:44:33 -0600 Subject: [PATCH] Added code to get a non-const char* from a std::string --- connect_code.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/connect_code.cpp b/connect_code.cpp index 5b83ff0..28db62f 100644 --- a/connect_code.cpp +++ b/connect_code.cpp @@ -11,8 +11,10 @@ namespace connect_code { /* Tokenizes a string, based on the given delimiter */ std::vector tokenize_str(std::string str, std::string delim) { std::vector 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) {