Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Does anyone know how to use the command line arguments with Visual C++?
I have used it in Linux like this:
void main (int argc, char* argv[])
and it worked fine, I wonder if it is possible in windows/Visual C++!Your response is really appreciated.

Visual C++ works the same way:
void main(int argc, char* argv[])
argc contains the number arguments
argv[] is an array of pointers to character stringsargc equals number of arguments plus 1
argv has pointers to argc plus one strings:With no command line arguments (n=0)
argc equals 1
argv has pointers to 2 strings:
argv[0] contains the name of executable file
argv[1] contains nullWith n command line arguments
argc equals n + 1
argv has pointers to n + 2 strings:
argv[0] contains the name of executable file
argv[1] to argv[n] contains the arguments
argv[n+1] contains null

Thank you guys for responding.
Well, I tried it but it seem like I am missing something:
For me, when I run it in Linux environment, I use the g++ compiler and create the object output file ( by using the -o operator) and then I type this output file along with my input files in the command line.In VC++, to run the program I just click the "!" button so I did not know where to list my input files.
Any further help please?

Normally you do the same thing in Windows by opening a DOS command window.
If you want to test it in Visual C++ do this:
Select: Settings in Project menu
Select: Debug tab
Program Arguments: enter command line arguments here

Thank you egkenny, it did work..
Now I've one further problem, that is how to use a wild card in the command line arguments..
the program i am working on requires entering a punch of different files each time i run it,
for example if i have these files in the directory a1.txt a2.txt a3.txt b1.txt b2.txt b3.txt c1.txt c2.txt c3.txt,
to enter the files start with a I use the * wildcard so a*.txt will make the program (in the linux environment) recognizes 3 files, similarly I could enter *2.txt or *.txt.
When I did this in VC++ it did not work, it read a*.txt as 1 file and could not open it " because it actuall doesnot exist", I also tried % and _ as wildcards but neither has worked..
Any idea how to do this in VC++..
It is really painful to enter the file names one at a time especially when you know there might be more than 70 files per run.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |