如何在C++中找到对象数组的长度

如何在C++中找到对象数组的长度,c++,class,C++,Class,如何在C中找到对象数组的长度++ class patient { public: int id; char p_name[20]; char f_name[20]; char m_test[20]; char c_report[20]; }; void p_detials(patient s[]) { char ch='y'; int i=0; while(ch == 'Y' or ch == 'y') {

如何在C中找到对象数组的长度++

class patient
{
public:
    int id;
    char p_name[20];
    char f_name[20];
    char m_test[20];
    char c_report[20];

};
void p_detials(patient s[])
{
    char ch='y';
    int i=0;
    while(ch == 'Y' or ch == 'y')
    {
        cout<<"\nEnter Patient id : ";
        cin>>s[i].id;
        cout<<"Enter Patient Name :";
        cin>>s[i].p_name;
        cout<<"Patient's Fathers Name :";
        cin>>s[i].f_name;
        cout<<"Test of Patient :";
        cin>>s[i].m_test;
        cout<<"Pateint Report :";
        cin>>s[i].c_report;
        cout<<"\nEnter more Records (y/n) ? : ";
        cin>>ch;
        cout<<"\n";
        i++;
    }
}

int main()
{
    pateint s[100];
    p_details(s1);
    return 0;
}
调用p_details函数后如何查找此对象数组的长度
因为我想在其他函数中访问数组进行搜索,所以必须让它返回长度

#include <iostream>
using std::cin;
using std::cout;

class patient
{
public:
    int id;
    char p_name[20];
    char f_name[20];
    char m_test[20];
    char c_report[20];

};
int p_detials(patient s[]) // use int instead of void
{
    char ch='y';
    int i=0;
    while(ch == 'Y' or ch == 'y')
    {
        cout<<"\nEnter Patient id : ";
        cin>>s[i].id;
        cout<<"Enter Patient Name :";
        cin>>s[i].p_name;
        cout<<"Patient's Fathers Name :";
        cin>>s[i].f_name;
        cout<<"Test of Patient :";
        cin>>s[i].m_test;
        cout<<"Pateint Report :";
        cin>>s[i].c_report;
        cout<<"\nEnter more Records (y/n) ? : ";
        cin>>ch;
        cout<<"\n";
        i++;
    }
    return i; // return the length
}

int main()
{
    pateint s[100];
    int size = p_details(s1); // receive the returned length
    return 0;
}

使用std::vector。或者为数组长度向函数中添加参数。如果不能,则必须在单独的参数中传递长度。请不要大喊大叫,你不能。将大小传递给函数或选择C++方式。使用std::数组或std::向量。请不要对我们大喊大叫!!很好,请问s1在哪里?那可能是s。啊,我明白了。这个错误是由OP引入的。