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]);
1.4m articles
1.4m replys
5 comments
57.0k users