<localharbor@yahoo.ca> wrote in message...
> I am a newbie to c++, so maybe this one's too easy, tho apparently not
> for me:
>
> 1. I am using MS Visual Studio.
So sorry. You could fix that. (GCC MinGW)
>
> 2. I have a std::string variable.
> 3. Its value might contain embedded null chars.
#include <iostream>
#include <string>
#include <vector>
void CharDummy( char const *in, size_t sz ){
// do stuff with array 'in'
}
int main(){
std::string LongLineGoneBad(
"Say hello to the problem\0 in this line.");
std::cout<<"LongLineGoneBad.size()="
<<LongLineGoneBad.size()<<std::endl;
std::cout<<"LongLineGoneBad="<<LongLineGoneBad<<std::endl;
char const LongLineArray[]=("Say hello to the problem\0 in this line.");
std::cout<<"sizeof(LongLineArray)="
<<sizeof(LongLineArray)<<std::endl;
std::vector<char> vLine( LongLineArray,
LongLineArray + sizeof(LongLineArray) );
std::cout<<"vLine.size()="<<vLine.size()<<std::endl;
CharDummy( &vLine.at(0), vLine.size() );
return 0;
} // main()
/* -output-
LongLineGoneBad.size()=24
LongLineGoneBad=Say hello to the problem
sizeof(LongLineArray)=40
vLine.size()=40
*/
Try it and see if you get the same results.
--
Bob R
POVrookie