How to print all the 3 letters substrings of a given string in C++

1 Answer

0 votes
#include <iostream>

int main()
{
    std::string str = "cpp-pro";
    int size = str.size();
    
    for (int i = 0; i < size - 2; i++)
        std::cout << str.substr(i, 3) << "\n";
}
 
 
 
 
/*
run:
 
cpp
pp-
p-p
-pr
pro
 
*/

 



answered Dec 24, 2022 by avibootz

Related questions

...