How to get first letter of each word in a string with C++

1 Answer

0 votes
#include <string>
#include <iostream>

int main() {
    std::string str = "c++ php java python c# javascript go";
    std::string const delimiters{ " " };
 
    size_t index_start, pos = 0;
    while ((index_start = str.find_first_not_of(delimiters, pos)) != std::string::npos) {
        pos = str.find_first_of(delimiters, index_start + 1);
        std::cout << str.substr(index_start, 1) << "\n";
    }
}

 
 
 
/*
run:
 
c
p
j
p
c
j
g
 
*/

 



answered Nov 9, 2022 by avibootz
...