Thanks for your help guys. Got it all figured out.
Thanks for your help guys. Got it all figured out.
Dunno, it works for me:Originally Posted by Dawnson
Code:#include <string> #include <algorithm> #include <iostream> int main() { using namespace std; string message("Dawnson"); char letter = 'n'; string::size_type mycount = count(message.begin(), message.end(), letter); cout << mycount << endl; }
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
The type of mycount should be the string::difference_type, not string::size_type apparently.
It is too clear and so it is hard to see.
A dunce once searched for fire with a lighted lantern.
Had he known what fire was,
He could have cooked his rice much sooner.
Ah. Luckily, the result of std::count will be non-negative, the conversion from signed to unsigned is well defined, and if it is possible for the count to be greater than the maximum value of size_type, then we're probably doomed anyway since size() might return an incorrect valueOriginally Posted by King Mir
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)