How to get the substring before specific character in C++

1 Answer

0 votes
#include <iostream>

int main()
{
    std::string str = "c++ prog-ramming";
    
    int pos = str.find("-");
    
    std::string sub = str.substr(0 , pos);

    std::cout << sub;
}
 
 
 
 
/*
run:
 
c++ prog
 
*/

 



answered Dec 24, 2022 by avibootz

Related questions

...