This is sort of a weird question but I wrote a code that reads from a text file full of numbers as strings and converts them into integers. The file contains 400 numbers
and the program reads only 392
.
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using namespace std;
int main() {
string line;
ifstream read;
int a[20][20];
vector<int>v;
int m;
string y;
string lines [20] ;
read.open("/Users/botta633/Desktop/Untitled.txt",ios_base::binary);
while (read>>line){
y="";
for (int i=0; i<line.length(); i++) {
y+=line[i];
}
m=stoi(y);
v.push_back(m);
}
for (int i=0; i<20; i++) {
for (int j=0; j<20; j++) {
int k=i*20+j;
a[i][j]=v[k];
}
}
for (int i=0; i<20; i++) {
for (int j=0; j<20; j++) {
cout<<a[i][j]<<" ";
}
cout<<endl;
}
cout<<v.size()<<endl;
return 0;
}
when I tried to change the number of integers inside the file it did read just some of them as well.
the file looks like this
89 41
92 36
54 22
40 40