Suppose we have a string
std::string str; // some value is assigned
What is the difference between str.empty()
and str[0] =
Also, beware of the functions you'll use if you use C++ 11 or later version:
#include
#include
int main() {
std::string str("\0ab", 3);
std::cout << "The size of str is " << str.size() << " bytes.\n";
std::cout << "The size of str is " << str.length() << " long.\n";
std::cout << "The size of str is " << std::strlen(str.c_str()) << " long.\n";
return 0;
}
will return
The size of str is 3 bytes.
The size of str is 3 long.
The size of str is 0 long.