Remove odd indexed characters from a given string | C ++ program to implement the above approach ; Function to remove the odd indexed characters from a given string ; Stores the resultant string ; If current index is odd ; Skip the character ; Otherwise , append the character ; Return the result ; Driver Code ; Function call
#include <bits/stdc++.h> NEW_LINE using namespace std ; string removeOddIndexCharacters ( string s ) { string new_string = " " ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( i % 2 == 1 ) { continue ; } new_string += s [ i ] ; } return new_string ; } int main ( ) { string str = " abcdef " ; cout << removeOddIndexCharacters ( str ) ; return 0 ; }