My code is as follows:
std::cin >> str; for ( char c : str ) if ( c == 'b' ) vector.push_back(i) //while i is the index of c in str
Is this doable? Or I will have to go with the old-school for loop?
Assuming str is a std::string or other object with contiguous storage:
str
std::string
std::cin >> str; for (char& c : str) if (c == 'b') v.push_back(&c - &str[0]);
2.1m questions
2.1m answers
60 comments
57.0k users