Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <cstdlib>
- #include <iostream>
- #include <iterator>
- #include <vector>
- #include <string>
- #include <fstream>
- #include <algorithm>
- using namespace std;
- int verifyData(int val){
- if (val == 1)
- {
- cout << val << endl;
- return val;
- }
- else if (val == 0)
- {
- cout << val << endl;
- return val;
- }
- return 0;
- }
- void fromFile(string fileInp){
- ifstream ifs(fileInp.c_str());
- if (ifs.is_open()){
- try{
- //bool isValid = true;
- string val = "";
- while (ifs >> val){
- verifyData(atoi(val.c_str()));
- }
- }
- catch (int e){ // wyjatek - bo tak
- cout << "Exception " << e << endl;
- }
- }
- }
- void help()
- {
- cout << " Aby poprawnie uruchomic program nalezy podac w parametrach:" << endl;
- cout << "-i nazwaPlikuWejsciowego.txt" << endl;
- cout << "-o nazwaPlikuWyjsciowego.txt" << endl;
- cout << "-p liczba iteracji" << endl;
- cin.get();
- }
- int main(int argc, char* argv[])
- {
- string fileInp, fileOut;
- int i = 1;
- int iteration;
- vector<int> v2(5, NULL);
- vector<vector<int> > v2d2(1,v2);
- vector<vector<int> > v2d3(2,v2);
- for(int i=0;i<v2d2.size(); i++) {
- for (int j=0;j<v2d2[i].size(); j++)
- cout << v2d2[i][j] << " ";
- cout << endl;
- }
- if (argc == 7) // sprawdzanie argumentow
- {
- do
- {
- if (string(argv[i]) == "-i") {
- fileInp = argv[i + 1]; // plik wejsciowy
- }
- else if (string(argv[i]) == "-o") {
- fileOut = argv[i + 1]; // plik wyjsciowy
- }
- else if (string(argv[i]) == "-p") {
- iteration = atoi(argv[i + 1]); // liczba iteracji
- }
- else // gdy bledny argument
- {
- cout << "Wrong arguments in the command line" << endl;
- }
- i = i + 2;
- } while (i < argc);
- if (iteration == 0) // jezeli jezeli iteracja rowna zero
- cout << "the number of iterations equal to zero" << endl;
- else if ((iteration > 1) && (iteration < 100000)) // jezeli ok
- {
- fromFile(fileInp);
- for (int i=0; i < iteration; i++)
- {
- cout << "Works fine! Iteration: " << i+1 << endl;
- cin.get();
- }
- }else
- {
- cout << "wrong value of parameters" << endl;
- }
- }
- else if (string(argv[i]) == "-h") // pomoc
- {
- help();
- }
- else // gdy wszystko zawiedzie
- {
- help();
- }
- //_CrtDumpMemoryLeaks();
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement