Running a c++ program
-
Hi Guys, Please help me in passing arguments for following c++ program http://msdn.microsoft.com/en-us/library/ms724926(v=VS.85).aspx[^] Thanks
vikas da
-
What do you mean 'passing arguments'? That code is complete and should compile and run without any additions.
The best things in life are not things.
-
I ran the program sucessfully with out put as "This sample takes a file name as a parameter". Now i am having a file like c:\temp.txt and i want to know timestamp for this what is supposed to be done for this.
vikas da
You'll have to provide the name of the file as command line parameter. For example lets consider the compiled executable is called TimeStamp.exe. Execute the program from the command line (console): TimeStamp.exe c:\textfile.txt As the name implies it, a command line parameter is passed from the command line. In the code you've linked you can see how the parameter is accessed using the argv array.
modified on Monday, May 23, 2011 7:52 AM
-
You'll have to provide the name of the file as command line parameter. For example lets consider the compiled executable is called TimeStamp.exe. Execute the program from the command line (console): TimeStamp.exe c:\textfile.txt As the name implies it, a command line parameter is passed from the command line. In the code you've linked you can see how the parameter is accessed using the argv array.
modified on Monday, May 23, 2011 7:52 AM
-
I do not see any such exe in my Debug or Release folder,I am using VS 2008 Pro. Apart from that i have to use this sample in one of my application to find the creation timestamp of a file,so help me achieving that same. Thanks,
vikas da
The builded exe is in your Release and / or Debug folder. Look for it. I didn't say the exe will be called TimeStamp.exe at you local PC! It was just an example. The name of the exe depends on your Project Settings (the project name by default). But then if you want to use only the logic shown in the code that you've linked in a program of yours, of course you don't need to build this exe at all but rather use the code that fullfills the desired task. And then again you dont have to provide the filename as command line parameter. This is totally up to you. For the beginning .. it would for your case probably enough if you change the following line.
hFile = CreateFile(argv[1], GENERIC_READ, FILE_SHARE_READ, NULL,OPEN_EXISTING, 0, NULL);
The argv[1] here contains the file name. You could also hard code this filename like
hFile = CreateFile("C:\tmp.txt", GENERIC_READ, FILE_SHARE_READ, NULL,OPEN_EXISTING, 0, NULL);
You'd also have to remove this if you dont want the code to be dependent of the number of command line parameters..
if( argc != 2 )
{
printf("This sample takes a file name as a parameter\n");
return 0;
}Or get the filename somewhere else. i dont know what you want to do but you'll have to think of stuff like that for yourself. I strongly advise you to go through some basic C/C++ tutorials, since you seem to lack some basic understandings of the language here.
-
I do not see any such exe in my Debug or Release folder,I am using VS 2008 Pro. Apart from that i have to use this sample in one of my application to find the creation timestamp of a file,so help me achieving that same. Thanks,
vikas da
Having compiled and built this program you must have a program (xxx.exe?) in either your Debug or Release folder; check again. This is a simple console program that can be run in a command prompt window (are you really saying you do not understand this basic facility?) thus:
ProgramName C:\filename.txt
In order to add this functionality to your own project you can just copy and paste the relevant parts of the sample into your own project.
The best things in life are not things.
-
Hi Guys, Please help me in passing arguments for following c++ program http://msdn.microsoft.com/en-us/library/ms724926(v=VS.85).aspx[^] Thanks
vikas da
Maybe you should start here first.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Some people are making such thorough preparation for rainy days that they aren't enjoying today's sunshine." - William Feather