Build error with structs

Asked

Viewed 78 times

0

The following error is happening in the compilation of the code below:

..\src struct.cpp:19:19: error: Elements of array 'main():ficaha v [3]' have incomplete type .. src struct.cpp:19:19: error: Storage size of 'v' isn’t known

Code:

#include <string>
#include <iostream>
using namespace std;
#define N 3
struct ficha{
    string nome;
    int idade;
    int reg;
};

int main() {
    struct ficaha v[3];
    int id;
    for (int i=0;i<N;i++){
        cout << "\n\nDgite o NOME do aluno " << i;
        getline(cin,v[i].nome);
        cout << "\n\nDgite a IDADE do aluno " << i;
        cin >> v[i].idade;
        cout << "\n\nDgite o REGISTRO do aluno " << i;
        cin >> v[i].reg;
    }
    cout << "Digite uma idade: ";
    cin >> id;
    cout <<"\nDados dos alunos com idade menor que "<<id<<": "<<endl;
    for (int i=0;i<N;i++){
        if ((v[i].idade) < id){
            cout << v[i].nome << " - " << v[i].idade;
        }
    }
    return 0;
}

This is my first exercise in structs and apparently I did exactly as I learned and I’m not seeing any error in the code.

Thanks in advance for your attention!

  • 4

    stay? I think to call the structure must by the same name stated previously.

1 answer

2

stay

The compilation error is quite clear and explanatory:

..\src struct.cpp:19:19: error: Elements of array 'main()::stay v [3]' have incomplete type

And you have it in the code:

struct ficha{
...
struct ficaha v[3];

And obviously "record sheet" and "Fictoha" are two completely different names for the compiler, "stay" is a typo.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.