Guest User

Code Review C++

a guest
Aug 28th, 2013
7
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.07 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <vector>
  4. #include <string>
  5. #include <sstream>
  6. #include "sub.h"
  7.  
  8. int main()
  9. {
  10.     std::ifstream file;
  11.     file.open(...);
  12.  
  13.     if (!file) {
  14.         std::cerr << "Error opening file." << std::endl;
  15.         return EXIT_FAILURE;
  16.     }
  17.  
  18.     int n;
  19.     std::string firstLine;
  20.     getline(file, firstLine);
  21.     std::stringstream(firstLine) >> n;
  22.  
  23.     int a,b,c;
  24.     std::vector<int> A1,B1,C1;
  25.     while (file >> a >> b >> c) {
  26.         A1.push_back(a);
  27.         B1.push_back(b);
  28.         C1.push_back(c);
  29.     }
  30.  
  31.     file.close();
  32.  
  33.     std::ofstream output;
  34.     output.open(...);
  35.  
  36.     output << n << "\n";
  37.  
  38.     size_t size = A1.size();
  39.     for (size_t i=0; i<size; ++i) {
  40.         output << A1[i] << " " << B1[i] << " " << C1[i] << std::endl;
  41.     }
  42.  
  43.     //call sub method with pointer to beginning of vectors
  44.     //I have no control over sub method, its signature is (int, int*, int*, int*)
  45.     int n1 = sub(n, &A1[0], &B1[0], &C1[0]);
  46.  
  47.     //output result and close file
  48.     output << n1;
  49.     output.close();
  50. }
Advertisement
Add Comment
Please, Sign In to add comment