fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. int main ()
  5. {
  6. std::string str("This is a test string");
  7. std::cout << "str = \"" << str << "\"\n";
  8. std::vector<size_t> t;
  9. for(size_t n = str.find_first_of("tT"); n != std::string::npos;
  10. n = str.find_first_of("tT", n+1))
  11. {
  12. std::cout << '\'' << str[n] << "' found at position " << n << ";\n";
  13. t.push_back(n);
  14. }
  15.  
  16. std::cout << "Searching complete\n"
  17. << "int t[" << t.size() << "] = {";
  18. if(!t.empty())
  19. {
  20. for(size_t n = 0; n < t.size()-1; ++n)
  21. std::cout << t[n] << ", ";
  22. std::cout << *t.rbegin();
  23. }
  24. std::cout << "}\n";
  25. }
  26.  
Success #stdin #stdout 0.02s 2860KB
stdin
Standard input is empty
stdout
str = "This is a test string"
'T' found at position 0;
't' found at position 10;
't' found at position 13;
't' found at position 16;
Searching complete
int t[4] = {0, 10, 13, 16}