Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Running a c++ program

Running a c++ program

Scheduled Pinned Locked Moved C / C++ / MFC
c++visual-studiocomhelp
8 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tasumisra
    wrote on last edited by
    #1

    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

    L D 2 Replies Last reply
    0
    • T tasumisra

      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

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      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.

      T 1 Reply Last reply
      0
      • L Lost User

        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.

        T Offline
        T Offline
        tasumisra
        wrote on last edited by
        #3

        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

        L 1 Reply Last reply
        0
        • T tasumisra

          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

          L Offline
          L Offline
          Legor
          wrote on last edited by
          #4

          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

          T 1 Reply Last reply
          0
          • L Legor

            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

            T Offline
            T Offline
            tasumisra
            wrote on last edited by
            #5

            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

            L L 2 Replies Last reply
            0
            • T tasumisra

              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

              L Offline
              L Offline
              Legor
              wrote on last edited by
              #6

              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.

              1 Reply Last reply
              0
              • T tasumisra

                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

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                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.

                1 Reply Last reply
                0
                • T tasumisra

                  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

                  D Offline
                  D Offline
                  David Crow
                  wrote on last edited by
                  #8

                  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

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups