fork(1) download
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <vector>
  5.  
  6. using namespace std;
  7.  
  8. int main(int argc, char* argv[]) {
  9. string fileName(argv[1]);
  10. fstream file(fileName, ios::in);
  11.  
  12. int numbersCount;
  13. vector<int> numbers;
  14.  
  15. file >> numbersCount;
  16. numbers.resize(numbersCount);
  17. for(int i = 0; i < numbersCount; ++i)
  18. file >> numbers[i];
  19.  
  20. for(const int& number : numbers)
  21. cout << number << ' ';
  22. cout << "Total numbers: " << numbers.size();
  23. return 0;
  24. }
Runtime error #stdin #stdout #stderr 0s 3468KB
stdin
data.txt
stdout
Standard output is empty
stderr
terminate called after throwing an instance of 'std::logic_error'
  what():  basic_string::_S_construct null not valid