X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=CppExamples%2FCOMPO_CXX_SRC%2Fsrc%2FCALCUL%2FCALCUL_CXX%2Fmain.cxx;fp=CppExamples%2FCOMPO_CXX_SRC%2Fsrc%2FCALCUL%2FCALCUL_CXX%2Fmain.cxx;h=ffb95346c4cb12dc01546d7af041f6b938188c4e;hb=eb23d5150f3cd1715528ba0a4668b93a7700591f;hp=0000000000000000000000000000000000000000;hpb=94653e5198a62ab14a74f61c21a4e62141158a21;p=tools%2Fhxx2salome.git diff --git a/CppExamples/COMPO_CXX_SRC/src/CALCUL/CALCUL_CXX/main.cxx b/CppExamples/COMPO_CXX_SRC/src/CALCUL/CALCUL_CXX/main.cxx new file mode 100644 index 0000000..ffb9534 --- /dev/null +++ b/CppExamples/COMPO_CXX_SRC/src/CALCUL/CALCUL_CXX/main.cxx @@ -0,0 +1,48 @@ +#include "Calc.hxx" +#include +#include +#include + +using namespace std; +int main(int argc, char ** argv) +{ + if (argc != 2) + { + cerr << "Usage : " << argv[0] + << "Calc.exe file.in" << endl << endl + << "-> lit le fichier file.in et exécute les commandes" << endl; + exit(-1); + } + ifstream in(argv[1], ios::in); + CALCUL myCalc; + int i1,i2; + string name; + + + string buf_ligne; // pour lire une ligne + while ( getline(in, buf_ligne) ) // parse le fichier d'entree + { + if( (buf_ligne.find("MUL")) != string::npos) + { + istringstream buf(buf_ligne.c_str()); + buf >> name >> i1 >> i2; + cout << "MUL(" << i1 << "," << i2 << ")=" << myCalc.mul(i1,i2) << endl; + } + else if (buf_ligne.find("ADD") != string::npos) + { + istringstream buf(buf_ligne.c_str()); + buf >> name >> i1 >> i2; + cout << "ADD(" << i1 << "," << i2 << ")=" << myCalc.add(i1,i2) << endl; + } + else if (buf_ligne.find("FACT") != string::npos) + { + istringstream buf(buf_ligne.c_str()); + buf >> name >> i1; + cout << "FACT(" << i1 << ")=" << myCalc.fact(i1) << endl; + } + } + + + in.close(); + +}