i have a code where i count the numbers of integers in txt file (there is a million integers)
now i want to copy these integers into the linked list for further operations. how can i do that?
#include <iostream>
#include <fstream>
#include <stdlib.h> // for exit(1) in the code below
#include <ctime>
using namespace std;
int main(){
size_t sz = 0; // total num of integers
int line;
fstream file;
file.open("numbers.txt");
if(file.fail()){
cerr << "Error opening the file" << endl;
exit(1); // closing application without any crashing
}
while(file >> line){
++sz;
}
cout << "There is totally " << sz << " numbers in the text file" << endl;
cout << "============" << endl;