可能性の重複:私はちょうど機能
std::string.c_str()
のように、std::vector<char>
からchar*
を取得するにはどうすればよい
Is it possible to get the pointer the continous memory fragment in a std::vector<char> in C++?のChar * ::ベクトル<char>
?
可能性の重複:私はちょうど機能
std::string.c_str()
のように、std::vector<char>
からchar*
を取得するにはどうすればよい
Is it possible to get the pointer the continous memory fragment in a std::vector<char> in C++?のChar * ::ベクトル<char>
?
最初の要素のアドレスください:あなたが行うことができます... space_cowboyの答えに少し拡大するため
を
char * foo = &my_vec[0];
を:
std::vector<char> vec;
vec.push_back('a');
vec.push_back('b');
vec.push_back('c');
char *arr = &vec[0];
しかし、あなたが今までだったらdo push_back
...
vec.push_back('d');
arr; // This pointer has been possibly invalidated!
// realloc could have been called on vec's memory.