struct Student
{
int num;
string name;
string classname;
float score[2];
float aver_score;
};
void averagescore(Student [],int);
int highaveragescoer(Student [],int);
//就提示下面这些信息:
g:\c++ work\lab1_2.h(7) : error C2146: syntax error : missing ';' before identifier 'name'
g:\c++ work\lab1_2.h(7) : error C2501: 'string' : missing storage-class or type specifiers
g:\c++ work\lab1_2.h(7) : error C2501: 'name' : missing storage-class or type specifiers
g:\c++ work\lab1_2.h(8) : error C2146: syntax error : missing ';' before identifier 'classname'
g:\c++ work\lab1_2.h(8) : error C2501: 'string' : missing storage-class or type specifiers
g:\c++ work\lab1_2.h(8) : error C2501: 'classname' : missing storage-class or type specifiers
8 个解决方案
#1
加上#include<string>
#2
小弟刚学C++,求各位大神赐教一下啊~~小弟不胜感激...
#3
加了,没有用啊
#4
把结构体声明放在cpp文件了,加上#include<string>有用,在.h里加就没用啊~~
#5
using std::string;
或者
using namespace std;
#6
//全部程序是这样滴:
//Lab1_2.h
struct Student
{
int num;
string name;
string classname;
float score[2];
float aver_score;
};
void averagescore(Student [],int);
int highaveragescoer(Student [],int);
//Lab1_2_1
#include <iostream>
#include <string>
using namespace std;
#include "Lab1_2.h"
void averagescore(Student stu[],int number);
int highaveragescoer(Student [],int);
int main()
{
Student stu[20];
int stu_number = 0;
cout << "please enter student number:";
cin >> stu_number;
for (int i = 0;i < stu_number;i++)
{
cout << "please enter NO." << i << "student info:num name classname score1,score2:";
cin >> stu[i].num >> stu[i].name >> stu[i].classname >> stu[i].score[0] >> stu[i].score[1];
}
averagescore(stu,20);
return 0;
}
//Lab1_2_2
#include "Lab1_2.h"
int highaveragescore(Student stu[],int number)
{
……
}
void averagescore(Student stu[],int number)
{
……
}
//Lab1_2.h
struct Student
{
int num;
string name;
string classname;
float score[2];
float aver_score;
};
void averagescore(Student [],int);
int highaveragescoer(Student [],int);
//Lab1_2_1
#include <iostream>
#include <string>
using namespace std;
#include "Lab1_2.h"
void averagescore(Student stu[],int number);
int highaveragescoer(Student [],int);
int main()
{
Student stu[20];
int stu_number = 0;
cout << "please enter student number:";
cin >> stu_number;
for (int i = 0;i < stu_number;i++)
{
cout << "please enter NO." << i << "student info:num name classname score1,score2:";
cin >> stu[i].num >> stu[i].name >> stu[i].classname >> stu[i].score[0] >> stu[i].score[1];
}
averagescore(stu,20);
return 0;
}
//Lab1_2_2
#include "Lab1_2.h"
int highaveragescore(Student stu[],int number)
{
……
}
void averagescore(Student stu[],int number)
{
……
}
#7
把所有的#include 都放到文件的前部
#8
okay,初学C++,非常感谢~!
#1
加上#include<string>
#2
小弟刚学C++,求各位大神赐教一下啊~~小弟不胜感激...
#3
加了,没有用啊
#4
把结构体声明放在cpp文件了,加上#include<string>有用,在.h里加就没用啊~~
#5
using std::string;
或者
using namespace std;
#6
//全部程序是这样滴:
//Lab1_2.h
struct Student
{
int num;
string name;
string classname;
float score[2];
float aver_score;
};
void averagescore(Student [],int);
int highaveragescoer(Student [],int);
//Lab1_2_1
#include <iostream>
#include <string>
using namespace std;
#include "Lab1_2.h"
void averagescore(Student stu[],int number);
int highaveragescoer(Student [],int);
int main()
{
Student stu[20];
int stu_number = 0;
cout << "please enter student number:";
cin >> stu_number;
for (int i = 0;i < stu_number;i++)
{
cout << "please enter NO." << i << "student info:num name classname score1,score2:";
cin >> stu[i].num >> stu[i].name >> stu[i].classname >> stu[i].score[0] >> stu[i].score[1];
}
averagescore(stu,20);
return 0;
}
//Lab1_2_2
#include "Lab1_2.h"
int highaveragescore(Student stu[],int number)
{
……
}
void averagescore(Student stu[],int number)
{
……
}
//Lab1_2.h
struct Student
{
int num;
string name;
string classname;
float score[2];
float aver_score;
};
void averagescore(Student [],int);
int highaveragescoer(Student [],int);
//Lab1_2_1
#include <iostream>
#include <string>
using namespace std;
#include "Lab1_2.h"
void averagescore(Student stu[],int number);
int highaveragescoer(Student [],int);
int main()
{
Student stu[20];
int stu_number = 0;
cout << "please enter student number:";
cin >> stu_number;
for (int i = 0;i < stu_number;i++)
{
cout << "please enter NO." << i << "student info:num name classname score1,score2:";
cin >> stu[i].num >> stu[i].name >> stu[i].classname >> stu[i].score[0] >> stu[i].score[1];
}
averagescore(stu,20);
return 0;
}
//Lab1_2_2
#include "Lab1_2.h"
int highaveragescore(Student stu[],int number)
{
……
}
void averagescore(Student stu[],int number)
{
……
}
#7
把所有的#include 都放到文件的前部
#8
okay,初学C++,非常感谢~!