Command-line arguments: Difference between revisions
Content added Content deleted
m (→{{header|C++}}: Minor formatting changes) |
|||
Line 617: | Line 617: | ||
Command line arguments are passed the same way as in C. |
Command line arguments are passed the same way as in C. |
||
This example uses iostream. |
This example uses <code><iostream></code>. C-style i/o also works. |
||
<syntaxhighlight lang="cpp">#include <iostream> |
<syntaxhighlight lang="cpp">#include <iostream> |
||
int main(int argc, char* argv[]) |
int main(int argc, const char* argv[]) { |
||
⚫ | |||
{ |
|||
<< "There are " << argc - 1 << " arguments given.\n"; |
|||
⚫ | |||
std::cout << "There are " << argc-1 << " arguments given." << std::endl; |
|||
std::cout << "The argument #" << i << " is " << argv[i] << '\n'; |
|||
⚫ | |||
⚫ | |||
return 0; |
|||
}</syntaxhighlight> |
}</syntaxhighlight> |
||