Printing string length in C++


This is a C++ program that uses the string class to create a string containing all the letters of the alphabet, and then prints the length of the string.

The string class is part of the standard C++ library, and provides a convenient way to work with strings of characters. In this program, the string word is initialized with the letters of the alphabet. The length() function is then called on the word string, which returns the number of characters in the string. This value is then printed to the console using the cout object.

Overall, this program simply demonstrates how to use the string class and its length() function in C++ to get the length of a string.

Source Code

#include<iostream>
#include<string.h>
using namespace std;
int main()
{
    string word = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    cout<<"\nThe length of the word string is: "<<word.length();
    return 0;
}
To download raw file Click Here

Output

The length of the word string is: 26

Program List


Flow Control

IF Statement Examples


Switch Case


Goto Statement


Break and Continue


While Loop


Do While Loop


For Loop


Friend Function in C++


String Examples


Array Examples


Structure Examples


Structure & Pointer Examples


Structure & Functions Examples


Enumeration Examples


Template Examples


Functions


Inheritance Examples

Hierarchical Inheritance


Hybrid Inheritance


Multilevel Inheritance


Multiple Inheritance


Single Level Inheritance


Class and Objects

Constructor Example


Destructor Example


Operator Overloading Example


Operator and Function Example


List of Programs


Pointer Examples


Memory Management Examples


Pointers and Arrays


Virtual Function Examples