Originally Posted by
Ducky
So if I understand well if I put a whole file in the char vector, 1 letter will be 1 element of the vector?
Thats not good for me because I cannot assign that to a char * buf.
Remember I need to assign the vector to a char* pointer.
Code:
void functionThatTakesCharPtr( char* ptr, std::size_t numberOfElements )
{
for ( std::size_t i = 0; i < numberOfElements; ++i )
{
ptr[ i ] = .....;
}
}
std::vector< char > vec( 5000, '\0' );
functionThatTakesCharPtr( &vec.at( 0 ), vec.size() );
std::vector was specifically designed to be compatible with old C-style interfaces that fiddle around with arrays and pointers.