C++ code to count letters in a string

In C++, by using the isupper(int) and islower(int) functions to indicate whether a character is an upper case letter or a lower case letter, you can count the upper case and lower case letters in a string.


#include <cstdlib>
#include <iostream>
#include <conio.h>

using namespace std;

void countUpperLower(){
  string st="C++ programming";
  int countup=0, countlo=0,i;
    if(isupper(st[i])) countup++;
    else if(islower(st[i])) countlo++;
  cout<<"Number of upper case letters:"<<countup<<"\n";
  cout<<"Number of lower case letters:"<<countlo<<"\n";


int main(){

return 0;


This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.
Copyright @ 2011-2013 worldbestlearningcenter. All Rights Reserved.