fork download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. int main()
  5. {
  6. {
  7. const std::string str = "Random irrelevent text here $500.22+$200.33 More random $irrelevent text$" ;
  8. std::cout << str << "\n character '$' found at positions: " ;
  9. std::string::size_type pos = str.find( '$' ) ;
  10. while( pos != std::string::npos )
  11. {
  12. std::cout << pos << ' ' ;
  13. pos = str.find( '$', pos+1 ) ;
  14. }
  15. }
  16.  
  17. {
  18. const std::string str = "\n\nRandom text here 50-people more random text" ;
  19. std::cout << str << "\n substring '50-people' found starting at position: "
  20. << str.find( "50-people" ) << '\n' ;
  21. if( str.find( '$' ) == std::string::npos ) std::cout << " character '$' was not found\n" ;
  22. }
  23. }
  24.  
Success #stdin #stdout 0s 3028KB
stdin
Standard input is empty
stdout
Random irrelevent text here $500.22+$200.33 More random $irrelevent text$
    character '$' found at positions: 28 36 56 72 

Random text here 50-people more random text
    substring '50-people' found starting at position: 19
    character '$' was not found