how to get size of a string in c++ code example
Example 1: c++ string size
str.length();
str.size();
Example 2: how to get string length in c++
#include <iostream>
#include <string>
int main()
{
string str = "iftee";
int len = str.length();
cout << "The String Length: " << len << endl;
int len2 = str.size();
cout << "The String Length: " << len2 << endl;
return 0;
}
Example 3: c++ string size
#include <iostream>
#include <string>
int main ()
{
std::string str ("Test string");
std::cout << "The size of str is " << str.size() << " bytes.\n";
return 0;
}