Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
185 views
in Technique[技术] by (71.8m points)

Getting an error while passing array variable of a pointer to structure

A program to display data information of 5 students. This is the error message I keep getting: (error: cannot convert 'student*' to 'student**'). FYI, in passing by value , the code executes without any problem. Can you please help me this issue? Thank you!

#include<iostream>
#include<cstring>
using namespace std;

struct student
{
    string name;
    int roll;
    int phone;
};

void display(struct student *st[5]) //Function to print information of each student
{
       int i;
       cout<<"Printing information of each student"<<endl;
       for(i=0; i<5; i++)
       {
            cout<<"
Student "<<i+1<<endl;
            cout<<"Name: "<<st[i]->name<<endl;
            cout<<"Roll number: "<<st[i]->roll<<endl;
            cout<<"Phone number: "<<st[i]->phone<<endl;
       }
}

int main()
{
    struct student s[5];//an array variable having 5 elements of structure student.
    int i;

    cout<<"Enter the information of each student"<<endl;
    for(i=0; i<5; i++)
    {
        cout<<"Information of student "<<i+1<<endl;
        cout<<"Enter name: ";
        cin.ignore(); //Clears unwanted input buffer before taking the next input (string)
        getline(cin,s[i].name);
        cout<<"Enter roll number: ";
        cin>>s[i].roll;
        cout<<"Enter phone number: ";
        cin>>s[i].phone;
    
        cout<<endl; //New line after data input for each student
    }
    display(s); //Passing the address of the structure variable 's' as an argument to the function 
    return 0;
}

 
question from:https://stackoverflow.com/questions/65926337/getting-an-error-while-passing-array-variable-of-a-pointer-to-structure

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...