C++ Array Input from File -
The code below has two input two separate .txt files designed. Each file contains a different integer on each line, reads the code file below, and stores each value in an array's index. The input works great, and while the cout command in the loop prints the appropriate value for the line.
This issue comes with COAT & lt; & Lt; Settobo [0] & lt; & Lt; Endl; It prints random values out of the loop as if the array's indicator is not set. Im Completely confused
set2.txt
1 3 9 2
code
Int maxSize = 100; Int'l set on [Max's]; Int Setovo [MaxSee]; Int setOneSize = 0; Int setTwoSize = 0; // open files ifstream file one ("set1.txt"); Ifstream file two ("set2.txt"); Int number; Int number 2; Fileon & gt; & Gt; Number; FileTwo & gt; & Gt; number 2; Announce the array for // (Ent I = 0; I & lt; MAXSize; i ++) {while (fileOne.good ()) {setOne [i] = Number; Cout & lt; & Lt; "Set 1" & lt; & Lt; Set On [i] & lt; & Lt; Endl; Fileon & gt; & Gt; Number; SetOneSize + = 1; } While (fileTwo.good ()) {setTwo [i] = number2; Cout & lt; & Lt; "Set 2" & lt; & Lt; Set-Two [i] & lt; & Lt; Endl; FileTwo & gt; & Gt; number 2; SetTwoSize + = 1; }} Cout & lt; & Lt; Settobo [0] & lt; & Lt; Endl;
Well, I believe it should print enough determinative values, In your example, it is always 2.
The code you typed is bad, firstly, you have to start the variable in number
and number 2
Have forgotten.
Secondly, at the time of the loop, you overwrite the first element in the two arrays with the value of the previous reading, which is the 2
in setTwo [0] /> At the end of the execution
Third, the size of the ARM starting with the non-constant variable is not actually standard in C ++
Comments
Post a Comment