I need to check whether my vector contains all null characters and perform some operation based on that result. I found couple of questions in Stack overflow but they are not exactly matching my requirement.
One solution that I can think of to decide a vector with all null characters is:
if(Buffer[0] == '\0') {
std::cout<<"vector contains all NULL characters";
}
If there is any better way for this, please share your idea.
Complete code is:
File1.cpp:
std::vector<unsigned char> Buffer(BufferSize, 0);
File2.cpp:
try
{
// do some operation, if no exception then fill the buffer
// if exception then go to catch block
}
catch(...)
{
memset(Buffer, '\0', BufferSize);
}
After this, in File1.cpp I just get Buffer, filled with valid data or '\0'.
This is in C++ 98