c++ - Strange output after reading from a file -


Using this code, the following execution results in strange results:

  C 100 RW  

The first line of the text file defines the number of elements to read this, and it has 15 values, but every time I run it, my The first value of the array is always printed as 87 (ASCII value for 'W') if I say 'W' Ability to convey changes in the 'X', the first results in the array is 88.

  #include & lt; Iostream & gt; # Include & lt; Fstream & gt; using namespace std; Int array lime; Class ELEMENT {Public: int key; }; Square HEAP {public: integer capability; Integer shape; ELEMENT H []; }; HEAP start (int n) {HEAP h; H.capacity = n; H.size = 0; Return H; } Zero buildup (HEAP & H, ELEMENT * A) {h.size = arrayLength; For (int i = 1; i & lt; = array langith; i ++) {hh [ii] = a [i]; } (Int i = h.size / 2; i & gt; = 1; i--) {// heffee here}} zero print hap (hip and h) {cout & lt; & Lt; "Capacity: \ t" & lt; & Lt; H.capacity & lt; & Lt; Endl; Cout & lt; & Lt; "Size: \ t \ t" & lt; & Lt; H.size & lt; & Lt; Endl; Cout & lt; & Lt; "|"; (Int i = 1; i & lt; = h.size; i ++) for {cout & lt; & Lt; ""; Cout & lt; & Lt; HHH [i] .k & lt; & Lt; "|"; } Cout & lt; & Lt; Endl; } Int main () {char c; Int valve; Hip h; While (c! = 'S') {cin> & Gt; C; Switch (c) {case 's': break; Case 'C': cin & gt; & Gt; Val H = start (val); break; Case 'W': printhead (h); break; Case 'R': {ifstream infile; Infile.open ("HEAPinput.txt"); Infile & gt; & Gt; ArrayLength; ELEMENT * a = new element [Sarrendant]; For (Int i = 1; I & lt; = Array Langith; I ++) Infel & gt; & Gt; A [i] .key; Infile.close (); Buildhead (H, A); }                 break; }} Return 0; }  

This is being compiled using G ++ on UNIX servers.

Edit: To clarify: With a text file with the following content (space = new line):

  12 9 10 11 12 8 7 6 5 4 3 2 1  

Output is:

  Capacity: 100 Size: 12 | 87 | 10 | 11 | 12 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 |  

Then it is working in addition to the first element

Whatever you think

  ELEMENT H [];  

is not, it is probably not C ++ does not support dynamic arrays - you have to use the std :: vector class.

and use the UPTX for BTW, C ++ pre-processor macros and constants by the conference. You should use mixed case for the names of your classes.


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -