How to find the index of the first occurrence of a character in a string in C++

1 Answer

0 votes
#include <iostream>
  
int main() {
    std::string s = "c++ php python";
    
    std::cout << s.find('p');

    return 0;
}
  
  
  
  
/*
run:
  
4
  
*/

 



answered Dec 9, 2020 by avibootz
...