Error: no match for call to (std::vector<char>) (int&)

I get this error inside all of the for loops for the multiArrayCipher function.

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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#include <iostream>
#include <cmath>
#include <string>
#include <fstream>
#include <vector>

using namespace std;

class functions
{
    public:
        char alphabet[26];
        int counter=0;
        string sentance;

        void input ()
        {
            cout << endl;
            cout << "Write a sentence: ";
            getline(cin,sentance);

        }

        void subCipher ()
        {
            cout << endl << "The new version is ";

            for (int i=0;i<sentance.length();i++)
            {
                if (sentance[i]==' ')
                    {
                        cout << " ";
                    }

                for (int j=0;j<26;j++)
                {
                    if (alphabet[j]==alphabet[23] && sentance[i]==alphabet[23])
                    {
                        cout << alphabet[0];
                    }

                    else if (alphabet[j]==alphabet[24] && sentance[i]==alphabet[24])
                    {
                        cout << alphabet[1];
                    }

                    else if (alphabet[j]==alphabet[25] && sentance[i]==alphabet[25])
                    {
                        cout << alphabet[2];
                    }

                    else if (alphabet[j]==sentance[i])
                    {
                        cout << alphabet[j+3];
                    }
                }
            }
            cout << endl << endl;
        }

        void multiArrayCipher()
        {
            vector <char> multiArrayOne;
            vector <char> multiArrayTwo;
            vector <char> multiArrayThree;
            vector <char> multiArrayFour;

            for (int j=0;j<sentance.length();j+=4)
            {
                multiArrayOne.push_back(1);
                multiArrayOne(counter)=sentance[j];
                counter++;
            }

            counter=0;

            for (int j=1;j<sentance.length();j+=4)
            {
                multiArrayTwo.push_back(1);
                multiArrayTwo(counter)=sentance[j];
                counter++;
            }

            counter=0;

            for (int j=2;j<sentance.length();j+=4)
            {
                multiArrayThree.push_back(1);
                multiArrayThree(counter)=sentance[j];
                counter++;
            }

            counter=0;

            for (int j=3;j<sentance.length();j+=4)
            {
                multiArrayFour.push_back(1);
                multiArrayFour(counter)=sentance[j];
                counter++;
            }

            cout << endl << endl;



        }
};

int main()
{
    functions program;
    int input;

    ifstream file;
    file.open("alphabet.txt");

    for (int j=0; j<26;j++)
    {
        file >> program.alphabet[j];
    }

    while (input!=5)
    {
        cout << "1. Substitution cipher" << endl;
        cout << "2. Multi-array cipher" << endl;
        cout << "3. Transposition cipher" << endl;
        cout << "4. Code breaker" << endl;
        cout << "5. Exit" << endl << endl;
        cout << "Enter the number of the option you want to proceed with: ";
        cin >> input;
        cin.ignore();

        switch (input)
        {
            case 1:
                program.input();
                program.subCipher();
                break;

            case 2:
                program.input();
                program.multiArrayCipher();


        }

    }


    return 0;
}

 
does this help?

multiArrayTwo[counter]=sentance[j];

you did this all over. Most of the time vectors are accessed with [] not (); the only common use of () is to reserve space
vector <char> hassize(1000); //() used to get space
hassize[3] = 'x'; //[] used to access, though.
Last edited on
closed account (E0p9LyTq)
multiArrayOne(counter) is a function call.

multiArrayOne[counter] accesses an element of the vector.
Topic archived. No new replies allowed.