Question about a command..

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • genyue

    Question about a command..

    Hi,

    For example, to run the complied program, I have to type 'compo'
    through MS-DOS. My question - how can I write a code when typing 'compo
    C:\text.txt' to create a text document (.txt) file, considering the
    ..txt file as "made.txt", with the word 'C:\text.txt' on the first line
    of the "made.txt" file?

  • msalters

    #2
    Re: Question about a command..



    genyue schreef:[color=blue]
    > Hi,
    >
    > For example, to run the complied program, I have to type 'compo'
    > through MS-DOS. My question - how can I write a code when typing 'compo
    > C:\text.txt' to create a text document (.txt) file, considering the
    > .txt file as "made.txt", with the word 'C:\text.txt' on the first line
    > of the "made.txt" file?[/color]

    The first step you need is to get the command line arguments. They're
    passed to main, but in asomewhat inconvenient form. So use this:

    #include <vector>
    #include <string>
    int main( int argc, char** argv ) {
    std::vector<std ::strings> args (argv, argv+argc);
    // you now have args[0] ... args[args.size()-1]
    }

    HTH,
    Michiel Salters

    Comment

    • Alan Johnson

      #3
      Re: Question about a command..

      msalters wrote:[color=blue]
      >
      > genyue schreef:
      >[color=green]
      >>Hi,
      >>
      >>For example, to run the complied program, I have to type 'compo'
      >>through MS-DOS. My question - how can I write a code when typing 'compo
      >>C:\text.txt ' to create a text document (.txt) file, considering the
      >>.txt file as "made.txt", with the word 'C:\text.txt' on the first line
      >>of the "made.txt" file?[/color]
      >
      >
      > The first step you need is to get the command line arguments. They're
      > passed to main, but in asomewhat inconvenient form. So use this:
      >
      > #include <vector>
      > #include <string>
      > int main( int argc, char** argv ) {
      > std::vector<std ::strings> args (argv, argv+argc);
      > // you now have args[0] ... args[args.size()-1]
      > }
      >
      > HTH,
      > Michiel Salters
      >[/color]

      Nitpick correction:
      std::vector<std ::string> args (argv, argv+argc);
      (original had an extra 's' character)

      -Alan

      Comment

      • Rapscallion

        #4
        Re: Question about a command..

        Alan Johnson wrote:[color=blue]
        > std::vector<std ::string> args (argv, argv+argc);
        > (original had an extra 's' character)[/color]

        Doesn't work anyway.

        Comment

        • red floyd

          #5
          Re: Question about a command..

          Rapscallion wrote:[color=blue]
          > Alan Johnson wrote:
          >[color=green]
          >>std::vector<s td::string> args (argv, argv+argc);
          >>(original had an extra 's' character)[/color]
          >
          >
          > Doesn't work anyway.
          >[/color]
          BS. Have you tried it? It works fine on any standard compliant compiler.

          Comment

          • Alan Johnson

            #6
            Re: Question about a command..

            Rapscallion wrote:[color=blue]
            > Alan Johnson wrote:
            >[color=green]
            >>std::vector<s td::string> args (argv, argv+argc);
            >>(original had an extra 's' character)[/color]
            >
            >
            > Doesn't work anyway.
            >[/color]

            It does rely on your compiler supporting "member templates", but those
            have been part of C++ for something like 7 years now.

            Comment

            Working...