처음으로 큰 도움을 주신 모든 분들께 감사드립니다!C++ 구조체 배열을 하나씩 전달 - 너무 단순하지만기만당했습니다.
전체 배열이 아니라 한 번에 하나의 변수를 전달하려고합니다. 나는 내가 가깝다는 것을 알고 있지만, 나는 수색하고 찾았고 내가 잘못하고있는 것을 발견 할 수 없다. 이
내가 말하는 점점 오전 오류는 말한다
무효 PrintRecords (studentRec & myRec)
함께 : 필드 'PrintRecords'에 대한 변수가 무효
#include <iostream>
using namespace std;
struct studenRec {
string name;
string address;
string city;
string state;
string zip;
char gender;
string myid;
float gpa;
};
void PrintRecords(studenRec& myRec);
int main()
{
studenRec myRec[3];
for (int i = 0; i < 3; i++) {
cout << "Students name: ";
getline(cin, myRec[i].name);
cout << "Students address: ";
getline(cin, myRec[i].address);
cout << "Students city: ";
getline(cin, myRec[i].city);
cout << "Students state: ";
getline(cin, myRec[i].state);
cout << "Students zip: ";
getline(cin, myRec[i].zip);
cout << "Students gender: ";
cin >> myRec[i].gender;
cin.ignore(1000,10);
cout << "Students id: ";
getline(cin, myRec[i].myid);
cout << "Students gpa: ";
cin >> myRec[i].gpa;
cin.ignore(1000,10);
cout << "STUDENT RECORDED SUCCESSFULLY" << endl;
cout << endl;
}
cout << "-------------------------------" << endl;
for (int i = 0; i < 3; i++) {
PrintRecords(myRec[i]);
}
return 0;
} // main
void PrintRecords(studentRec& myRec)
{
cout << "Students name: " << myRec.name << endl;
cout << "Students address: " << myRec.address << endl;
cout << "Students city: " << myRec.city << endl;
cout << "Students state: " << myRec.state << endl;
cout << "Students zip: " << myRec.zip << endl;
cout << "Students gender: " << myRec.gender << endl;
cout << "Students id: " << myRec.myid << endl;
cout << "Students gpa: " << myRec.gpa << endl;
cout << endl;
}
지금보고있는 동작은 무엇입니까? 추락? 예기치 않은 행동? 컴파일러 오류? 뭐가 나왔어? 숙제 인 경우 "숙제"로 태그하십시오. –
'cin >> gender;를 입력 한 후 문제가 발생합니까? (이것은'char' 변수를 제출할 때'scanf()'에서 흔히 발생하는 문제입니다.) – iammilind
void PrintRecords를 사용하여 3 개의 에러를 얻었습니다 ... studentRec이이 범위에서 선언되지 않았고 myRec이이 범위에서 선언되지 않았다 , 변수 또는 필드 'PrintRecords'가 공백으로 선언되었습니다 – CodingIsAwesome