Difference between revisions of "Effective Analysis Programming Part 2"

From Gridkaschool
m (Created page with "==C++ Templates== ====exercise 1: pair==== ====exercise 2: read paramerters==== <source lang="cpp"> #define MAIN_CPP #include <iostream> #include <exception> #include "readpar…")
 
m (exercise 2: read paramerters)
Line 4: Line 4:
   
 
====exercise 2: read paramerters====
 
====exercise 2: read paramerters====
  +
  +
  +
<source lang="bash">
  +
# GKS 2013
  +
answer 42
  +
parser_test "\\\"" "#" #should result in \" and #
  +
useful yes
  +
</source>
  +
  +
 
<source lang="cpp">
 
<source lang="cpp">
 
#define MAIN_CPP
 
#define MAIN_CPP

Revision as of 17:18, 23 August 2013

C++ Templates

exercise 1: pair

exercise 2: read paramerters

# GKS 2013
answer 42
parser_test "\\\"" "#" #should result in \" and #
useful yes


#define MAIN_CPP

#include <iostream>
#include <exception>
#include "readparameters.h"

using namespace std;

int main(int argc,char **argv){ 
  //check arguments
  if (argc!=2) {
    cerr<<"Usage: ./params <paramfile>"<<endl;
    return 1;
  } 
  
  //get input filename from parameter file
  int answer;
  vector<string> v;
  try { 
      readparameters rp(argv[1]);
      answer = rp.get<int>("answer");
      v=rp.get_vector<string>("parser_test");
      cout<<answer<<endl;
      rp.print_tabular(); //debug output
      rp.get<long>("Atlantis"); //exception
      
  }
  catch (exception& e) {
      cerr<<e.what()<<endl;
      return 1;
  }

  return 0;
}