我正在尝试将我的student_info
结构与我的read_name
函数相关联,但我遇到了使其正常工作并且无法编译的问题。我现在得到的错误是error: ‘first_name’ was not declared in this scope
和error: ‘last_name’ was not declared in this scope
。然而,我在结构中声明了它们。
这是我的代码:
#include <iostream>
using namespace std;
//Place your structure here for Step #1:
struct student_info
{
char first_name[15];
char last_name[15];
char crn[15];
char course_designator[15];
int section;
};
//Place any prototypes that use the structure here:
void read_name(student_info & first_name[], student_info & last_name[])
{
cout << "enter first name" << endl;
cin.getline(first_name, 15, '\n');
cout << "enter last name" << endl;
cin.getline(last_name, 15, '\n');
first[0] = toupper(first_name[0]);
last[0] = toupper(last_name[0]);
cout << "your name is " << first_name << " " << last_name << endl;
}
int main()
{
//For Step #2, create a variable of the struct here:
student_info student;
read_name(first_name, last_name);
return 0;
}
答案 0 :(得分:1)
您可以采取哪些措施来解决问题。
更改read_name
以引用student_info
。
void read_name(student_info & student)
更改read_name
的实施,将数据读入first_name
的{{1}}和last_name
成员。
info
从void read_name(student_info & student)
{
cout << "enter first name" << endl;
cin.getline(student.first_name, 15, '\n');
cout << "enter last name" << endl;
cin.getline(student.last_name, 15, '\n');
first[0] = toupper(student.first_name[0]);
last[0] = toupper(student.last_name[0]);
cout << "your name is " << student.first_name << " "
<< student.last_name << endl;
}
开始,使用main
作为参数调用read_name
。
student