Reading integers from .dat file and collecting them in a vector

时间:2016-06-18 20:19:31

标签: c++

I am trying to read integers located in a dat file. I thought that this is the correct way to approach this problem but nothing prints out to the console and when I try to print out an index from vector nothing shows up indicating that nothing is actually being store in the vector. I would appreciate any help. Thank you!

 vector<int> nums;
 ifstream myfile;
 myfile.open("nums.dat");
 int a = 0;

 while (myfile >> a) {
     nums.push_back(a);
 }



 for (int i = 0; i < nums.size(); i++) {
     cout << nums.at(i) << endl;
 }





 return 0;

0 个答案:

没有答案