]> SALOME platform Git repositories - tools/hxx2salome.git/blob - CppExamples/COMPO_CXX_SRC/src/CALCUL/CALCUL_CXX/main.cxx
Salome HOME
ffb95346c4cb12dc01546d7af041f6b938188c4e
[tools/hxx2salome.git] / CppExamples / COMPO_CXX_SRC / src / CALCUL / CALCUL_CXX / main.cxx
1 #include "Calc.hxx"
2 #include <iostream>
3 #include <fstream>
4 #include<sstream>
5
6 using namespace std;
7 int main(int argc, char ** argv)
8 {
9     if (argc != 2)
10     {
11         cerr << "Usage : " << argv[0]
12             << "Calc.exe file.in" << endl << endl
13             << "-> lit le fichier file.in et exécute les commandes" << endl;
14         exit(-1);
15     }
16     ifstream in(argv[1], ios::in);
17     CALCUL myCalc;
18     int i1,i2;
19     string name;
20
21
22     string buf_ligne; // pour lire une ligne
23     while ( getline(in, buf_ligne) ) // parse le fichier d'entree
24     {
25         if( (buf_ligne.find("MUL")) != string::npos)
26         {
27             istringstream buf(buf_ligne.c_str());
28             buf >> name >> i1 >> i2;
29             cout << "MUL(" << i1 << "," << i2 << ")=" << myCalc.mul(i1,i2) << endl;
30         }
31         else if (buf_ligne.find("ADD") != string::npos)
32         {
33             istringstream buf(buf_ligne.c_str());
34             buf >> name >> i1 >> i2;
35             cout << "ADD(" << i1 << "," << i2 << ")=" << myCalc.add(i1,i2) << endl;
36         }
37         else if (buf_ligne.find("FACT") != string::npos)
38         {
39             istringstream buf(buf_ligne.c_str());
40             buf >> name >> i1;
41             cout << "FACT(" << i1 << ")=" << myCalc.fact(i1) << endl;
42         }
43     }
44             
45
46     in.close();
47
48 }