Convert characters of a string to opposite case | C ++ program to toggle all characters ; Function to toggle characters ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void toggleChars ( string & S ) { for ( auto & it : S ) { if ( isalpha ( it ) ) { it ^= ( 1 << 5 ) ; } } } int main ( ) { string S = " GeKf @ rGeek $ " ; toggleChars ( S ) ; cout << " String ▁ after ▁ toggle ▁ " << endl ; cout << S << endl ; return 0 ; }