Hi,
How to convert vector<char> to char* ?
thnx
Hi,
How to convert vector<char> to char* ?
thnx
Given a vector<char> x with at least one element, you can write: &x[0]
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
thank you
With the newest C++ standard you can use x.data() to get a pointer to the data as well.
The data member function is also available.
std::vector::data - cppreference.com
You have to remember that unlike std::string::data(), std::vector::data() will not give you a sequence with null-character at the end.
std::string::data isn't guaranteed to either. Although enough programmers rely on it to anyway, so most implementations will. But properly, you should use std::string::c_str if you want a null terminated string.
It is too clear and so it is hard to see.
A dunce once searched for fire with a lighted lantern.
Had he known what fire was,
He could have cooked his rice much sooner.