Error: no match for 'operator='

I'm getting very strange errors with the code down below, could someone explain why?

ERROR 1: no match for 'operator=' in 'siff[i] = siff_varde[j]'
ERROR 2: request for member 'size' in 'siff', which is of non-class type... bla bla bla
ERROR 3: no match for 'operator+=' in 'sum+=siff[k]'
ERROR 4: no match for 'operator-=' in 'sum-=siff[k]'

No match for operator '='? Are they kidding me? This isn't even my code, it's from a book so it should be working...

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
30
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main(){
    const string rom_siff = "IVXLDM";
    const int siff_varde[6] = {1,5,10,50,100,1000};
    string s;
    cout << "Skriv in ett romerskt tal: "; cin >> s;
    if(s.size()==0 || s.find_first_not_of(rom_siff)!=string::npos)
        cout << "Du skrev inte in ett romerskt tal!";
    else{
        vector<int> siff[s.size()+1];
        for(int i=0;i<s.size();i++){
            int j;
            for(j=0;s[i]!=rom_siff[j];j++)
                ;
            siff[i] = siff_varde[j]; // ERROR 1 ON THIS LINE!
        }
        int sum=0;
        for(int k=0;k<siff.size();k++){   // ERROR 2 ON THIS LINE!
            if(siff[k]>siff[k+1])
                sum += siff[k];      // ERROR 3 ON THIS LINE!
            else
                sum -= siff[k];      // ERROR 4 ON THIS LINE!
            cout << sum << endl;
        }
    }
}
Last edited on
Hi Göran!

vector<int> siff[s.size()+1];
This creates an array of s.size()+1 vectors.

If you want siff to be a vector of size s.size()+1 you should use parentheses.
vector<int> siff(s.size()+1);
Last edited on
@ Peter87

It's incredible how these small faults change the outcome of the whole code, oh well, thanks for the help :)
Are you Scandinavian by the way?
Yes, I'm a Swede, and so are you ;)
Yep :)
Has anyone got any clue on how to do the same program as I did up here, but backwards? Meaning that you enter a number and you get a Roman number back. The only solution I see is a enormous tree of if-statements, however, I'm not very skilled at this.
Last edited on
Topic archived. No new replies allowed.