i dont really know whats wrong with this, but its super basic.
im not done writing the program yet, im still missing some input prompts for the user, but as i am testing my current program, i keep getting an error message that says

line 70 - name lookup of 'j' changed for new ISO 'for' scoping
line 68 - using obsolete binding at 'j'

does anyone have any idea what this means?

to get a better understanding, my current code is below...

#include <fstream>
#include <iomanip>
#include <string>
#include <iostream>
using namespace std;

struct Student
{
  string name;
  int id;
  float gpa;
};

void printStudents(Student* student, int nStudents)
{
  int i;
  for (i = 0; i < nStudents; i++)
  {
    cout << "Name = " << left << setw(30)  << student[i].name;
    cout.fill('0');
    cout << " ID = "<< right << setw(7)
      << student[i].id << ", gpa = "
      << student[i].gpa  << endl;
    cout.fill(' ');
  }
}

int main()
{
  // open a file for input
  
  
  // create an empty list
  const int MAX_STUDENTS = 100;   // capacity
  int nStudents = 0;              // initially empty 
  Student student[MAX_STUDENTS];
  
  // read and save the records
  while (true)
  {
    // create a record and read it from file
    Student aStudent;
    getline(cin, aStudent.name);
    
    cin >> aStudent.id;
    cin.ignore(1000, 10);
    
    cin >> aStudent.gpa;
    cin.ignore(1000, 10);
    
    cin.ignore(1000, 10);         // skip the -------------- separator
    
    // add record to list, if it's not full
    if (nStudents < MAX_STUDENTS)
      student[nStudents++] = aStudent;
    
  }

  // sort the students by name
  for (int i = 0; i < nStudents; i++)
  {
    for (int j = i + 1; j < nStudents; j++);
    {
      if (student[i].name > student[j].name)
      {
        Student temp = student[i];
        student[i] = student[j];
        student[j] = temp;
      }
    }
  }
  
  printStudents(student, nStudents);
  
  cin.ignore();
  cin.get();
  return 0;
}

Hey,
You have a semi-colon placed after your for loop declaration.

for (int j = i + 1; j < nStudents; j++); <-- delete this semi-colon
{
if (student.name > student[j].name)
{
Student temp = student;
student = student[j];
student[j] = temp;
}
}

"line 68 - using obsolete binding at 'j' "
You get this error because the semi-colon makes that line do nothing. Since j has a lifetime only for that one line, j does not have any effect on the program and is obselete.


"line 70 - name lookup of 'j' changed for new ISO 'for' scoping"
I believe you get this error because the old scoping for 'for' loops was:

for(int i=0; i<someValue; i++)
{
//can use i here
}

int j = i; // this used to be valid

but then got changed so that the lifetime of 'i' would be only for the 'for' loop:

for(int i=0; i<someValue; i++)
{
//can use i here
}

int j = i; //cannot use 'i' here because it is out of scope


Hope this helps.
Sorry for not using the code tags. I'm a first-time poster and I haven't learned how to use them yet.

mrjjkalyn

i dont really know whats wrong with this, but its super basic.
im not done writing the program yet, im still missing some input prompts for the user, but as i am testing my current program, i keep getting an error message that says

line 70 - name lookup of 'j' changed for new ISO 'for' scoping
line 68 - using obsolete binding at 'j'

does anyone have any idea what this means?

to get a better understanding, my current code is below...

#include <fstream>
#include <iomanip>
#include <string>
#include <iostream>
using namespace std;

struct Student
{
  string name;
  int id;
  float gpa;
};

void printStudents(Student* student, int nStudents)
{
  int i;
  for (i = 0; i < nStudents; i++)
  {
    cout << "Name = " << left << setw(30)  << student[i].name;
    cout.fill('0');
    cout << " ID = "<< right << setw(7)
      << student[i].id << ", gpa = "
      << student[i].gpa  << endl;
    cout.fill(' ');
  }
}

int main()
{
  // open a file for input
  
  
  // create an empty list
  const int MAX_STUDENTS = 100;   // capacity
  int nStudents = 0;              // initially empty 
  Student student[MAX_STUDENTS];
  
  // read and save the records
  while (true)
  {
    // create a record and read it from file
    Student aStudent;
    getline(cin, aStudent.name);
    
    cin >> aStudent.id;
    cin.ignore(1000, 10);
    
    cin >> aStudent.gpa;
    cin.ignore(1000, 10);
    
    cin.ignore(1000, 10);         // skip the -------------- separator
    
    // add record to list, if it's not full
    if (nStudents < MAX_STUDENTS)
      student[nStudents++] = aStudent;
    
  }

  // sort the students by name
  for (int i = 0; i < nStudents; i++)
  {
    for (int j = i + 1; j < nStudents; j++);
    {
      if (student[i].name > student[j].name)
      {
        Student temp = student[i];
        student[i] = student[j];
        student[j] = temp;
      }
    }
  }
  
  printStudents(student, nStudents);
  
  cin.ignore();
  cin.get();
  return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.