Counting every fucking vowels!

Hi fellas, I have a problem when I try to count every vowel in a txt file. Input and output when dealing with txt files is no problem. But in my program, I have to generate random ascii characters and put them inside a txt file. Then I have to count every vowel in every line. I can count all of them: capital and noncapital. But how can I make my program count all of the vowels, including those with strange simbols like '¨´' or any other?

Thanks!
Hi,

An ordinary char is a narrow type - they are straight ASCII chars, and doesn't have those accent marks. So an easy answer is to fill your file with these.

On the other hand a wchar can hold all kinds of chars.

If you use a switch statement, you can have a case which has all the chars you deem to be a vowel.

Really? But I've already defined my characters as "char" and I still get strange symbols. However, I've already made a very long "if statement" to count some vowels like "ä" and others. But it's too long and there's probably a better way to do that. Does anyone know how?
Generally, when you refer to "ASCII" characters, you're referring to those printable characters with values in the range [0,128) Characters outside that range are "extended ASCII" characters, and differ according to the environment you're in. (So, if you're using a different environment at school and home you may not get the same results.)

However, you could extend the following for your dubious goal if you wished:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
 // http://ideone.com/bD4TBL
#include <iostream>
#include <sstream>
#include <string>

std::string vowels("aeiouAEIOU");

bool contains(const std::string& s, char letter)
{
    return s.find(letter) != std::string::npos;
}

bool is_vowel(char ch)
{
    return contains(vowels, ch);
}

std::istringstream in("These are some words\n.  Everyone should know them.");

int main()
{
    std::size_t vowels = 0;
    char ch;

    while (in >> ch)
        vowels += is_vowel(ch);

    std::cout << "Counted " << vowels << " vowels.\n";
}
Oh, I see. Thanks!
Topic archived. No new replies allowed.