Hey Guys I keep getting this error:
Error 1 error C2109: subscript requires array or pointer type
it is the only error my program is showing here is my code:
// In a header file
//grades.h
#ifndef GRADES_H
#define GRADES_H
#include %26lt;iostream%26gt;
#include %26lt;string%26gt;
using namespace std;
struct Grades
{
string names;
int scores;
};
#endif
Weird Error in C++ Program Please Help.?
The problem is scores and names are not defined as
array. You are trying to access it as an arrary.
Remove [count]. That should solve this problem.
cout %26lt;%26lt; "Name:";
cin %26gt;%26gt; Grade.names;
cout %26lt;%26lt; "Test Score:";
cin %26gt;%26gt; Grade.scores;
Reply:not a C++ developer, but i believe it has something to do with your array, for instance in Grades you have string names and int scores
an example of what causes Error C2109
// C2109.cpp
int main() {
int a, b[10] = {0};
a[0] = 1; // C2109 ------ ERROR
b[0] = 1; // OK
}
Reply:not sure but instead of this :
Grade.scores[count];
wouldn't this be more appropriate
Grade[count].scores;
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment