C++ strlen() Function


C++ strlen() function gives the length of the given string.

strlen() function counts the number of characters in a given string and returns the integer value. Null character indicates the end of the string.

Null character indicates the end of the string.

C++ String length

Syntax:

Size_t strlen ( const char * str);

Example:

#include <iostream>   
#include <cstring>
using namespace std;

int main () {
    char str1[30] = "Welcome to";
    char str2[30] = " Onlinetpoint";
    int str3;
    strcat( str1, str2);
	cout << "String concatenate str1 & str2: " << str1 << endl;
    /* length of string str1 */
    str3=strlen( str1);
    cout << "Length of string str1 is: "<< str3 ;
    return 0;
}



OnlineTpoint is a website that is meant to offer basic knowledge, practice and learning materials. Though all the examples have been tested and verified, we cannot ensure the correctness or completeness of all the information on our website. All contents published on this website are subject to copyright and are owned by OnlineTpoint. By using this website, you agree that you have read and understood our Terms of Use, Cookie Policy and Privacy Policy.