read file, analyse characters



  • Hi community.
    In my current project I have to read a file and count the occurences of characters. Normal characters work fine ( like a-z), but I also need to analyse some special chars like ü,ä,ö.

    I began like this:

    int currentchar;
    vector<int> ascii(256, 0);
    
    textfile.open("text.txt");
        while(textfile >> line) {
            lastpos = line.size()-1;
            cout<<line<<endl; //displays the line in console codepage
            for(i = 0; i <= lastpos; i++) {
                //this should convert one character to its index on codepage
                currentchar = line[i];
                //this counts the characters
                ascii[currentchar]++;
            }
    
        }
    textfile.close();
    

    I saved it in Windows-Editor ("ANSI"-Encoding).
    When the algorithm analyses for example a line containing "ü", it displays the line in the right way (the "ü" is replaced by "³", cause this is index 252 in console-codepage). But when it comes to convert "³" to integer (the index) than i get huge numbers like 426...
    What can I do to get 252 as it stands for "³" in console and for "ü" in windows?

    mfg rider



  • correction:

    I saved the "text.txt" in ANSI-Encoding. (not "it").


Anmelden zum Antworten