Print the middle character of a string | C ++ program to implement the above approach ; Function that prints the middle character of a string ; Finding string length ; Finding middle index of string ; Print the middle character of the string ; Driver Code ; Given string str ; Function Call
#include <bits/stdc++.h> NEW_LINE using namespace std ; void printMiddleCharacter ( string str ) { int len = str . size ( ) ; int middle = len / 2 ; cout << str [ middle ] ; } int main ( ) { string str = " GeeksForGeeks " ; printMiddleCharacter ( str ) ; return 0 ; }