Get length of a string in C++

Download
Download is available until [expire_date]
  • Version
  • Download 15
  • File Size 1.29 KB
  • File Count 1
  • Create Date May 9, 2016
  • Last Updated May 9, 2016

Get length of a string in C++

Get length of a string in C++

A c++ program that will count the number of characters in a given string. The program will first ask the user to enter a string, then the length() property will count the number of characters in a string object.

Open the main.cpp in codeblocks or any ide that supports c++.

Source code:

#include < iostream >
#include

using namespace std;

int main()
{
    string mystring;
    cout << "Enter a string: " << endl;
    cin >> mystring;
    cout <<"the string has " << mystring.length() << " character(s)" << endl;
    return 0;
}
, , , , , ,

Post navigation

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.