Note that there are some explanatory texts on larger screens.

plurals
  1. POAttempting to create a queue - issue with crashing C++
    text
    copied!<p>For my data structures course I have to create a queue that takes input from a .dat file, and organizes it based on high priority (ONLY if it's 1) and low priority (2 3 4 or 5). There must be two queues, * indicates how many to service (or remove). The .dat file looks like:</p> <pre><code>R 3 T 5 W 1 A 4 * 3 M 5 B 1 E 1 F 2 C 4 H 2 J 1 * 4 * 1 D 3 L 1 G 5 * 9 = </code></pre> <p>Here's the main.cpp</p> <pre><code>int main () { arrayQueue myHigh; //creates object of arrayQueue arrayQueue myLow; //creates another object of arrayQueue while(previousLine != "=") //gets all the lines of file, ends program when it gets the line "=" { getline(datfile, StringToChar); if (StringToChar != previousLine) { previousLine=StringToChar; //sets previousline equal to a string number = StringToChar[2]; //the number of the data is the third line in the string istringstream ( number ) &gt;&gt; number1; //converts the string to int character = StringToChar[0]; //the character is the first line in the string } if (number1 == 1) //if number is 1, sends to high priority queue myHigh.addToQueue(number1); else if (number1 == 2 || number1 == 3 || number1 == 4 || number1 == 5) //if number is 2 3 4 or 5 sends to low priority queue myLow.addToQueue(number1); } datfile.close(); system ("pause"); } </code></pre> <p>And here's the array class:</p> <pre><code>void arrayQueue::addToQueue(int x) { if (full() == true) cout &lt;&lt; "Error, queue full \n"; else { fill = (fill+1)%maxSize; queueArray[fill] = x; cout &lt;&lt; x &lt;&lt; endl; //testing that number is actually being passed through count++; size++; } } </code></pre> <p>However, the output that I get is just:</p> <pre><code>3 5 </code></pre> <p>and then it crashes with no error.</p> <p>I'm not sure where I should go, I haven't created two objects of a class OR used a file to read data before in C++. Did I do that correctly? I think it's just feeding 3 and 5 into the high priority queue, even though it's not supposed to do that. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload