bad_array_new_length at memory location in C++

  • Thread starter Thread starter Arash_89
  • Start date Start date
A

Arash_89

Guest
Hello,

When I want to compile this program I have an error.

Unhandled exception at 0x76A335D2 in ConsoleApplication1c++.exe: Microsoft C++ exception: std::bad_array_new_length at memory location 0x0093F56C. occurred


#include<iostream>
#include<string>
using namespace std;
const int n = 2;
struct Courses
{
string name;
int numberOfUnit;
float Grade;
};

struct Student
{
int number;
string name;
string family;
int term;
int numberOfCourse;
float totalGrade;
string birthday;
int *listOfGrade = new int[term];
string* listOfCourses = new string[numberOfCourse];
Courses SplitCourses[3];
};

int main()
{

Student* myStudent = new Student[n];
Courses* myCourses = new Courses[n];
for (int i = 0; i < n; i++)
{
cin >> myStudent.number;
cin >> myStudent.name;
cin >> myStudent.family;
cin >> myStudent.term;
cin >> myStudent.numberOfCourse;
cin >> myStudent.totalGrade;
for (int j = 0; j < myStudent.term -1; j++)
{
cin >> myStudent.listOfGrade[j];
}
cin >> myStudent.birthday;
for (int j = 0; j < myStudent.numberOfCourse; j++)
{
cin >> myStudent.listOfCourses[j];
}

}
string delimiter = "/"; string s[3]; int K = 0;
string str;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < myStudent.numberOfCourse; j++)
{
str = myStudent.listOfCourses[j];
size_t pos = 0;
std::string token;
while ((pos = str.find(delimiter)) != std::string::npos) {
token = str.substr(0, pos);
s[i++] = token;
str.erase(0, pos + delimiter.length());
}
s[2] = str;
myStudent.SplitCourses[j].name = s[0];
myStudent.SplitCourses[j].numberOfUnit = stoi(s[1]);
myStudent.SplitCourses[j].Grade = stof(s[2]);
}
}

return 0;
}

Continue reading...
 

Similar threads

A
Replies
0
Views
186
Arash_89
A
A
Replies
0
Views
153
abc def ghi jkl mno pqrs tuv wxyz ABC DEF GHI JKL
A
Back
Top