Is there any way to determine the length of a string without the use of iterating through the string until you find the null terminator. Because in some code I have, some of the strings im trying to find the length of have '\0' all over the place, not just at the end
std::string str = "Hello world!";
std::cout << str.size(); // Prints the size of the string (12)
For C-style strings (char arrays), you'll have to use a character other than '\0', because that character is used specifically to designate the end of the string.
You could try to use a separate size variable and just keep track of the size yourself, but that doesn't help if you don't know the initial size beforehand.
@codegoggles - std:string won't work since the the OP states the data contains embeded nulls.
@OP - Since you say your data has embeded nulls, you're not dealing with conventional strings. Storing your data as a std::string or even a C-string isn't going to help. Since you can't rely on a null terminator, what determines the length of your data? As long double main suggested, you're going to need to keep track of the length yourself.
Also, I would prefer a begin and end pointer over a pointer and length. At the very least, have length be of type std::ptrdiff_t rather than std::size_t.