c++ argv argument not parsing * from command line -
i have issue *
character in command line input.
the commands these:
2.exe input.txt output.txt + 2 2.exe input.txt output.txt - 2 2.exe input.txt output.txt * 2
it works perfectly, except last one. somehow not *
character command line. if put '*'
works, not idea.
i searched web, , closest got globals being mentioned somewhere, not sure how it. here code
#include <iostream> #include <fstream> #include <cstdlib> using namespace std; int main(int argc, char * argv[]) { ifstream infile(argv[1]); ofstream outfile(argv[2]); if (infile.is_open() && infile.good()) { int num; int sum = 0; string arg = string(argv[3]); int val = atoi(argv[4]); while(infile >> num) { if(arg == "+") sum = num + val; else if(arg == "-") sum = num - val; else sum = num * val; cout << "sum: " << num << endl; cout << "sum: " << sum << endl; outfile << sum << " "; } outfile.close(); } else { cout << "faila ne se otvarq"; } return 0; }
because of shell expansion, *
expanded shell files in current directory, should use either
2.exe input.txt output.txt '*' 2
or
2.exe input.txt output.txt \* 2
Comments
Post a Comment