char* argv[]

Intrebari despre limbajul C++, standardul C++, STL, OOP in C++ sau alte subiecte nelegate de VisualC++
Post Reply
atty97
Junior
Junior
Posts: 5
Joined: 15 Jul 2012, 15:39
Judet: Cluj

char* argv[]

Post by atty97 » 05 Nov 2014, 15:00

Bună ziua!

Am început să învăț despre parametrii funcției main, știu ce sunt, ce fac (numără argumentele command-line și le păstrează în vectorul argv), dar nu știu la ce sunt folositoare aceste parametrii.
Îmi puteți spune, la ce sunt folositoare aceste parametrii?

Mulțumesc anticipat.



User avatar
Marius Bancila
Fondator
Fondator
Posts: 2344
Joined: 11 Jul 2007, 11:45
Judet: Timiş
Location: Timisoara
Contact:

Re: char* argv[]

Post by Marius Bancila » 09 Nov 2014, 00:57

Sunt folosite ca sa executi un program cu parametrii din linia de comanda. Nu intelegi la ce e asta util?
Marius Bancila
Fondator Codexpert, Microsoft MVP VC++
Site personal | Blog

atty97
Junior
Junior
Posts: 5
Joined: 15 Jul 2012, 15:39
Judet: Cluj

Re: char* argv[]

Post by atty97 » 09 Nov 2014, 13:28

Exact, nu inteleg le ce este util.

User avatar
Ovidiu Cucu
Fondator
Fondator
Posts: 3778
Joined: 11 Jul 2007, 16:10
Judet: Iaşi
Location: Iasi
Contact:

Re: char* argv[]

Post by Ovidiu Cucu » 09 Nov 2014, 19:02

Parametrii sunt folositi ca sa transmiti programului la lansare anumite informatii (de exemplu numele unui fisier) si/sau anumite optiuni.
Ca sa te lamuresti, lanseaza un utilitar cunoscut care vine cu sistemul Windows (de exemplu TASKLIST.exe) cu argumentul /?
La iesire obtii ceva de genul.

Code: Select all

C:\Users\Gigel>TASKLIST /?

TASKLIST [/S system [/U username [/P [password]]]]
         [/M [module] | /SVC | /V] [/FI filter] [/FO format] [/NH]

Description:
    This tool displays a list of currently running processes on
    either a local or remote machine.

Parameter List:
   /S     system           Specifies the remote system to connect to.

   /U     [domain\]user    Specifies the user context under which
                           the command should execute.

   /P     [password]       Specifies the password for the given
                           user context. Prompts for input if omitted.

   /M     [module]         Lists all tasks currently using the given
                           exe/dll name. If the module name is not
                           specified all loaded modules are displayed.

   /SVC                    Displays services hosted in each process.

   /V                      Displays verbose task information.

   /FI    filter           Displays a set of tasks that match a
                           given criteria specified by the filter.

   /FO    format           Specifies the output format.
                           Valid values: "TABLE", "LIST", "CSV".

   /NH                     Specifies that the "Column Header" should
                           not be displayed in the output.
                           Valid only for "TABLE" and "CSV" formats.

   /?                      Displays this help message.

Filters:
    Filter Name     Valid Operators           Valid Value(s)
    -----------     ---------------           --------------------------
    STATUS          eq, ne                    RUNNING |
                                              NOT RESPONDING | UNKNOWN
    IMAGENAME       eq, ne                    Image name
    PID             eq, ne, gt, lt, ge, le    PID value
    SESSION         eq, ne, gt, lt, ge, le    Session number
    SESSIONNAME     eq, ne                    Session name
    CPUTIME         eq, ne, gt, lt, ge, le    CPU time in the format
                                              of hh:mm:ss.
                                              hh - hours,
                                              mm - minutes, ss - seconds
    MEMUSAGE        eq, ne, gt, lt, ge, le    Memory usage in KB
    USERNAME        eq, ne                    User name in [domain\]user
                                              format
    SERVICES        eq, ne                    Service name
    WINDOWTITLE     eq, ne                    Window title
    MODULES         eq, ne                    DLL name

NOTE: "WINDOWTITLE" and "STATUS" filters are not supported when querying
      a remote machine.

Examples:
    TASKLIST
    TASKLIST /M
    TASKLIST /V /FO CSV
    TASKLIST /SVC /FO LIST
    TASKLIST /M wbem*
    TASKLIST /S system /FO LIST
    TASKLIST /S system /U domain\username /FO CSV /NH
    TASKLIST /S system /U username /P password /FO TABLE /NH
    TASKLIST /FI "USERNAME ne NT AUTHORITY\SYSTEM" /FI "STATUS eq running"
Ti-a afisat modul de folosire dandu-ti o lista cu parametri pe care poti sa-i transmiti la lansare. A dat chiar la sfarsit si cateva exemple practice.
Acei parametri ii primeste programelul respectiv (tasklist.exe) prin acel argv[] din main si ii prelucreaza in burta lui ca sa-si da seama ce vor muschii tai de la el.
Eh, acuma-i mai clar la ce-s buni? :)

atty97
Junior
Junior
Posts: 5
Joined: 15 Jul 2012, 15:39
Judet: Cluj

Re: char* argv[]

Post by atty97 » 10 Nov 2014, 01:00

Mutumesc foarte mult! :thumbsup:

Post Reply