fork download
  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <time.h>
  4. #include <string>
  5. #include <sstream>
  6. #include <fstream>
  7. #include <vector>
  8. #include <algorithm>
  9. #include <iterator>
  10.  
  11. using namespace std;
  12.  
  13. int main () {
  14. //Declarations for I/O files
  15.  
  16. ifstream inputFile;
  17.  
  18. //Open file list and count number of files
  19. inputFile.clear();
  20. inputFile.open("filelist.txt", ios::in);
  21.  
  22. //exit and prompt error message if file could not be opened
  23. if (!inputFile){
  24. cerr << "File list could not be opened" << endl;
  25. exit(1);
  26. }// end if
  27.  
  28. // count number of lines in the data file and prompt on screen
  29. int number_of_files = 0;
  30.  
  31. std::string line;
  32. while (getline(inputFile, line))
  33. number_of_files++;
  34.  
  35. cout << "Number of files to be analyzed: " << number_of_files << endl;
  36.  
  37. std::string *filelist;
  38. filelist = new string[number_of_files];
  39. inputFile.close();
  40.  
  41. //Re-open file list and store filenames in a string array
  42. inputFile.clear();
  43. inputFile.open("filelist.txt", ios::in);
  44.  
  45. //exit and prompt error message if file could not be opened
  46. if (!inputFile){
  47. cerr << "File list could not be opened" << endl;
  48. exit(1);
  49. }// end if
  50.  
  51. // store filenames
  52. int i = 0;
  53. while (getline(inputFile, line)){
  54. filelist[i] = line;
  55. //cout << filelist[i] << endl;
  56. i = i + 1;
  57. }
  58.  
  59. inputFile.close();
  60.  
  61. //open first file in the list, I deleted the loop to focus on the first element for now
  62.  
  63. inputFile.clear();
  64. inputFile.open(filelist[0].c_str(), ios::in);
  65.  
  66. //exit and prompt error message if file could not be opened
  67. if (!inputFile){
  68. cerr << "Data file could not be opened" << endl;
  69. exit(1);
  70. }// end if
  71. }
  72.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty