jeudi 5 décembre 2019

C++ 2 dimention pointer array initialization

If this looks familiar, it is. I asked a question on this last week but this time I am using pointers. I need to input the amount of candSize to initialize the array. If I take out the for loop, the function runs to insert a single char and a number for votes, function ends and I can print it so I know that is working as it should for now. My problem is where I try to get the 2nd dimension on the candList array. The '=' sign on the line after the for loop is getting a squiggly faulting for

'=' : cannot convert from 'char *' to 'char'

My text is showing this and it is the only option I have found here and other places, and they work.

#include<iostream>
#include<string>
#include<iomanip>
#include<array>
....
int main ( )
{
    int candSize, voteSize;
    cout << "Enter number of Candidates: ";
    cin >> candSize;
    cout << endl;
    voteSize = candSize;
    char *candList = new char[candSize];
    double *voteList = new double[voteSize];
    for (int a = 0; a < candSize;a++)
         candList[a] = new char[8];
    dataInput ( candList, voteList, candSize );

    for (int b = 0;b < candSize;b++)
    {
        cout << candList[b] << " ";
        cout << voteList[b];
        cout << endl;
    }
    system ( "Pause" );
}

Aucun commentaire:

Enregistrer un commentaire