Use string.length() to check the string's size : string size « String « C++






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

1.string.size()string.size()
2.string size grows
3.string.size(), string.length, string.capacity(), string.max_size()