Use string.length() to check the string's size
#include <iostream>
#include <string> // include for C++ standard string class
using namespace std;
int main()
{
string stringA = "C++";
string stringB = "Is Cool";
cout << "Length of stringA = " << stringA.length() << endl;
cout << "Length of stringB = " << stringB.length() << endl;
return 0;
}
/*
Length of stringA = 3
Length of stringB = 7
*/
Related examples in the same category