c++ - Core Dump Exception -
I have compiled this code successfully, but when I come around the last for the loop in the main, Get Dump Handle How Can I Fix It?
main.cpp
#include & lt; Iostream & gt; #include & lt; String & gt; # Include & lt; Fstream & gt; # Include & lt; Vector & gt; # Include "DRSequence.h" using the namespace std; Vector & lt; DRSequence & gt; Array; Int indexOfSequenceWithFirstWord (string word) {for (unsigned int cnt = 0; cnt & gt; array.size (); cnt ++) {DRSequence s = array [cnt]; If (word.compare (s.firstWord ()) == 0) Return CNET; } Return -1; } Int main (Int arc, four ** argv) {cout & lt; & Lt; "Open file:" & lt; & Lt; Argv [1] & lt; & Lt; "\ N"; String in; Ifstream Infographic; InFile.open (argv [1]); If (! Infile) {cout & lt; & Lt; "unable to open file"; Exit (1); Unsigned int cnt = 0; DRSequence sequence; While (inFile> gt; & gt;) {if (cnt% 2 == 0) {int index = indexOfSequenceWithFirstWord (in); If (index and lieutenant; 0) {sequence.setFirstWord (in); (Sequence) array.push_back; } And sequence = array [index]; } CNT ++; } InFile.close (); (CNT = 0; array size (); cnt ++) {DRSequence s = array [CNT]; S.description (); } Return 0; }
DRSquence.h
#include & lt; Iostream & gt; #include & lt; String & gt; # Include & lt; Vector & gt; using namespace std; Square DRSequence {string first; Vector & lt; DRSequence & gt; Array; integer number; Public: Zero Details () {cout & lt; & Lt; First & lt; & Lt; "\ N"; (Unsigned int cnt = 0; cnt & lt; array size (); cnt ++) {cout & lt; & Lt; "\ T" & lt; & Lt; Array [cnt] Firstworld () & lt; & Lt; "" & Lt; & Lt; Array [cnt] CountDegree () & lt; & Lt; "\ N"; }} Zero setfirst (string s1) {first = s1; } String first word () {back before; } Int countDegree () {Return calculation; } Zero addSecondWord (strings) {private}: int indexOfSequenceWithWord (string word) {for (unsigned int cnt = 0; cnt> array.size (); cnt ++} {DRSequence s = array [cnt]; If (word.compare (s.firstWord ()) == 0) Return CNET; } Return -1; }};
Your for-loop test is incorrect:
{Cnt = 0; array size (); cnt ++} { If there is an element in the array, then condition array.size ()
Will always evaluate for the right and it will always be a loop, where forever "until the array [cnt]
is at the end of the array and you get a break on access."
You mean that:
for (cnt = 0; cnt & lt; array.
Comments
Post a Comment