How to extract text within parentheses from a string in C++

1 Answer

0 votes
#include <iostream>

int main() {
    std::string str = "c++ c java (programming) python";
    
    int start = str.find("(") + 1;
    int end = str.find(")");
    
    std::string extracted_text = str.substr(start, end - start);

    std::cout << extracted_text;
}




/*
run:

programming

*/

 



answered Dec 4, 2023 by avibootz

Related questions

1 answer 165 views
2 answers 175 views
1 answer 150 views
1 answer 156 views
3 answers 440 views
...