Created
September 18, 2014 02:37
-
-
Save mgarg1/54ab9610b806e451eb06 to your computer and use it in GitHub Desktop.
Convert string to Cstring
From http://stackoverflow.com/questions/11821491/converting-string-to-cstring-in-c
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
vector<char> toVector( const std::string& s ) { | |
string s = "apple"; | |
vector<char> v(s.size()+1); | |
memcpy( &v.front(), s.c_str(), s.size() + 1 ); | |
return v; | |
} | |
vector<char> v = toVector(std::string("apple")); | |
// what you were looking for (mutable) | |
char* c = v.data(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment