c++ - Is this the correct way to read a .txt file into a 1-D array and then store data in that particular array? -


i wanted know if correct way store array of integers read in txt file , if close txt file values stored in arr[i] ??? appreciate quite new programming.

//includes. #include <iostream> #include <fstream>  using namespace std; int main(int argc, const char * argv[]) {  //declaring variables. int option; int total; int arr [12];  //create instance of fstream class (creating object of fstream class). ifstream infile; infile.open("arraylist.txt");  //check error. if(infile.fail()) {     cerr << "error opening file \n";     exit(1); }  //reading file array. for(int i=0; i<12; i++)     infile >> arr[i];  //close txt file. infile.close();  


Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -