Let's say. given the sentence: "I want to learn C ++." We need to find the number of occurrences of the letter "o" in the sentence. How to do this if the code below can only count Latin letters?

#include <iostream> #include <string> using namespace std; int main() { setlocale(LC_CTYPE, "Russian"); string s; getline(cin, s); int col = 0; for (int i = 0; i < s.size(); i++) { if (s[i] == 'О' || s[i] == 'о') col++; } cout << col; return 0; } 
  • Write instead of Latin Russians? ... taking into account the coding, of course. - Harry
  • @Harry, the fact of the matter is that he does not read Russian letters. More accurately reads in the console, but does not lead from the count. I tried to write in the branch Latin letters in the condition - everything robs. But with the Russian trouble - IWProgrammer
  • Considering that the author of the question writes "setlocale (LC_CTYPE," Russian ");" - it looks like it works under Windows. And that there is a mess of three encodings - he does not know. Therefore, there are several options - from the fact that in the editor to set the cp866 encoding or in the console to set cp1251 / utf (and in the editor as well). You can also override the input and output operators and work .... - KoVadim
  • @KoVadim, can you explain how to do this in a bit more detail? The first time I hear just about the "mash of 3 encodings" - IWProgrammer
  • @KoVadim Personally, I just spat and when it comes to the console, I write everything in 866 encoding, without suffering :) - Harry

0