- Version
- Download 17
- 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;
}