Thanks for your help guys. Got it all figured out.
Printable View
Thanks for your help guys. Got it all figured out.
Dunno, it works for me:Quote:
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;
}
The type of mycount should be the string::difference_type, not string::size_type apparently.
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 value :)Quote:
Originally Posted by King Mir