text: String containing first letter of every word in a given string with spaces | C ++ program to find the string which contain the first character of each word of another string . ; Function to find string which has first character of each word . ; Traverse the string . ; If it is space , set v as true . ; Else check if v is true or not . If true , copy character in output string and set v as false . ; Driver cpde
code: #include <bits/stdc++.h> NEW_LINE using namespace std ; string firstLetterWord ( string str ) { string result = " " ; bool v = true ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { if ( str [ i ] == ' ▁ ' ) v = true ; else if ( str [ i ] != ' ▁ ' && v == true ) { result . push_back ( str [ i ] ) ; v = false ; } } return result ; } int main ( ) { string str = " geeks ▁ for ▁ geeks " ; cout << firstLetterWord ( str ) ; return 0 ; }