This is my first thred here!

This code is for a glossary test from swedish to english.

I have problem with (*it).engelska)! And why cant i use (*it).engelska in this code?

Many Thanks in advance!!

void prov(list<Glosor> lista)
{
        string testet;
        int santal = 0;
        int rsvar = 0;
        list<Glosor>::iterator it;
        for(it = lista.begin(); it != lista.end(); it++){
            cout << (*it).svenska << " betyder på engelska: "; // *it writes the swedish word for translate.
            getline(cin, testet); //Here you write the english word and "if" function test if it's correct.
            if(testet == (*it).engelska){
                cout << "Ratt svar!\n";
                rsvar++;
                }
            else{
            cout << "Tyvärr fel svar rätt svar är: "<< (*it).engelska) << endl; // Here i use "it" to write the correct answare if you guess wrong. But it keep telling me "error: expected ';' before ')' token"
            }
            santal++;
        }
        cout << "Du hade " << rsvar << " rätt svar av " << santal << " möjliga" << endl;
}
有帮助吗?

解决方案

There is a closing parenthesis in line 15 after engelska that doesn't have a matching opening parenthesis:

cout << "Tyvärr fel svar rätt svar är: "<< (*it).engelska) << endl;
//                           here------------------------^

Also in the FOR loop @ line 7, use ++it instead of it++. The former doesn't create a copy of the iterator, meaning it performs faster.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top