C++ strlen Function: Usage Guide

The strlen function is used to calculate the length of a string, which means it returns the number of characters in the string, not including the trailing null character ‘\0’. Its usage is as follows:

#include <cstring>

const char *str = "Hello, World!";
int length = strlen(str);
cout << "String length: " << length << endl;

In the code above, the strlen function will return the length of the string “Hello, World!”, which is 13.

bannerAds