root/data/sphere/first_revision/test.cpp

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. readLine_until_string
  2. main

   1 #include <string>
   2 #include <sstream>
   3 #include <fstream>
   4 #include <iostream> 
   5 #include <exception>
   6 using namespace std;
   7 
   8 bool readLine_until_string(istream& is, string& s, const string& condition){
   9         getline(is,s);
  10         if(s == condition)
  11                 return false;
  12         return true;
  13 }
  14 
  15 int main(int argc, char *argv[])
  16 try{
  17         ifstream ifs {argv[1]};
  18         if(!ifs) throw runtime_error("File not found!");
  19         ofstream ofs {argv[2]};
  20 
  21         for(string s; readLine_until_string(ifs, s, "SIMPLEX");){
  22                 ofs << s << endl;
  23         }
  24         ofs << "SIMPLEX" << endl;
  25 
  26         for(string s; readLine_until_string(ifs, s, "#");){
  27                 double d1,d2,d3;
  28                 stringstream ss {s};
  29                 ss >> d1 >> d2 >> d3;
  30                 int i1 = d1-1, i2 = d2-1, i3 = d3-1;
  31                 ofs << i1 << ' ' << i2 << ' ' << i3 << endl;
  32         }
  33         ifs.close();
  34         ofs << "#\n#\n";
  35         ofs.close();
  36     return 0;
  37 }
  38 catch(exception& e){
  39         cerr << e.what() << '\n';
  40         return 1;
  41 }

/* [<][>][^][v][top][bottom][index][help] */