Thanks for your help guys. Got it all figured out.
This is a discussion on Please help with a c++ string within the C++ Programming forums, part of the General Programming Boards category; 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; }
C + C++ Compiler: MinGW port of GCC
Version Control System: Bazaar
Look up a C++ Reference and learn How To Ask Questions The Smart Way
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
![]()
C + C++ Compiler: MinGW port of GCC
Version Control System: Bazaar
Look up a C++ Reference and learn How To Ask Questions The Smart Way