Home > Back-end >  C program is abnormal
C program is abnormal

Time:09-28

I created this line dynamic one-dimensional array will appear abnormal:
0 x756d4192 (located on the map - project2. Exe) with untreated exception: Microsoft c + + exceptions: STD: : bad_array_new_length, located in the memory location 0 x003ff7d8,
Bosses also o solve

The code is as follows:
#include
#include
#include
#include
Using namespace STD.
The class dot {
Public:
Double x;
Double y;

};
The class line {
Public:
Int num.
The int type.
A double height;
Dots=new dot dot * (num);
};
Int scale;
The dot (p1, p2,
The line * allData;

Int getnum () {
Int Num=0;
Ifstream fin (" data. TXT ");
String t;

while (! Eof ())
fin.{
Getline (fin, t);
If (t=="71012" | | t=="71011")
Num++;
}
Return Num.
}
Void readfile () {
Int lineNum;
LineNum=getnum ();
AllData=https://bbs.csdn.net/topics/new line (lineNum);
A string of n;
Ifstream fin (" data. TXT ");
Do {
Getline (fin, n);
} while (n!="BEGIN");
Fin & gt;> Scale;
Fin & gt;> P1. X;
Fin & gt;> P2. X;
Fin & gt;> P1. Y;
Fin & gt;> P2. Y;

for (int i=0; I & lt; LineNum; I++) {
Fin & gt;> AllData [I] type;
Fin & gt;> AllData [I]. Height;
Fin & gt;> AllData [I] num;
For (int j=0; J & lt; AllData [I] num; J++) {
Fin & gt;> AllData [I]. Dots [j]. Journal of x;
Fin & gt;> AllData [I]. Dots [j]. J y;
}
}

/* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- */
for (int i=0; I & lt; LineNum; I++) {
Cout & lt; CoutFor (int j=0; J & lt; AllData [I] num; J++) {
Cout & lt; }
}

}


Int main () {
Readfile ();

}

CodePudding user response:

The class line {
Public:
Int num.//the num you have no assignment (early)
The int type.
A double height;
Dots=new dot dot * (num);//the num is a number of garbage, so may not be correct
};
  • Related