Author | Message |
---|
Sojiro Regular Posts: 50
| ok im about to quote a very simple piece of code, and a following paragraph of tutorial on how to use it, and how it works - regarding command line arguments, so its simple stuff...
Code: | using namespace std; int main(int argc, char *argv[]) { if(argc !=2){ cout << "Invalid number of command line arguments" << endl; cin.get(); return EXIT_FAILURE; } cout << "This is a " << argv[1] << endl; cin.get(); return EXIT_SUCCESS } |
Quote: | *Passing a command line argument to the prog...* "When you run it, pass the statistic as a command line argument (from the command line or through your IDE options/settings." "When I run this as 'ThisIsA.exe' and enter 'Statistic' on the command line (e.g. ThisIsA.exe Statistic) it produces the following output : This Is A Statistic. The first thing our program does is check that there are two arguments. The first is the name used to invoke the program and may include the path name. The second is 'Statistic'. If our program doesn't find two arguments (if you forgot to add 'Statistic' or if you entered more than one name) it outputs an error message and terminates the program. If there are two command line arguments the program uses the second, which is 'Statistic', and outputs it. Note that because the program has more than one exit point I've chosen to include the return statement at the end of main. I've also used EXIT_SUCCESS and EXIT_FAILURE as return values, and have included the header <cstdlib> accordingly." | My only question is, where exactly is the command line even better, feel free to post the above code with Statistic written into it. i have compiled this code some time ago, however reading back through the analysis i'd like to find out why this biatch aint gone as it was supposed to. i currently get the "This is a" output, but cant seem to add the Statistic via the explained technique mentioned in the quote. currently using this code with Dev-C++ ty 8)
|
Meka][Meka Unstopable Posts: 700
| ok once u have the app compiled u have the binary ye (.exe) for example, but this exe on ur desktop, open a dos prompt, 'cd' to your desktop dir, then type compiledexename.exe blah blah and u will see a result, an arguement result ;) for the text upasted below u might need to change the argv[1] to argv[0]
|
Sojiro Regular Posts: 50
|
Quoted from Meka][Meka | ok once u have the app compiled u have the binary ye (.exe) for example, but this exe on ur desktop, open a dos prompt, 'cd' to your desktop dir, then type compiledexename.exe blah blah and u will see a result, an arguement result ;) for the text upasted below u might need to change the argv[1] to argv[0] | kool m8 but, in the article i quoted from i should be seein that text mentioned through my compiler ;) surely theres another way other than via promptin'? but ty for that, ill check it out later n get back to this thread tommorow..
|
Sojiro Regular Posts: 50
| hmm ok it never done much good in terms of the tutorial :( but managed to progress in another area will prolly be posting another sos thread sometime soon anyway lol.. ty..
|