Thread: Command line arguments

  1. #1
    NotSoAvgProgrammer
    Join Date
    Jul 2007
    Location
    Virginia, U.S.
    Posts
    57

    Command line arguments

    I am trying to retrieve the command line arguments that are given to me.

    I am using msvc++ 2008

    Code:
    #include "stdafx.h"
    #include <iostream>
    #include <vector>
    #include <string>
    
    	
    
    
    
    int _tmain(int argc, char* argv[])
    {
    	std::cout<< *arg[0] << std::endl;;
    	std::cout<< argc;
    
    	return 0;
    }
    The above gives me
    j (the file name is jplib.exe)
    x = (the amount of arguments I give +1)

    If I change it to *arg[1], and I have one argument will give me the first letter to the first argument, and *arg[2], the first letter to the second argument, etc.

    I have tried using arg[1][1], but that returns null

    How do I get the command line arguments?

    Thank you for your time and effort,

    Joe
    A quality job is not necessarily a *good* job. A quality job is, by definition, conformance to requirements. Therefore a *good* job, may not be a quality job.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Read the FAQ
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    And use main if you use a char argv, not _tmain. _tmain is the Win32 Unicode switchy thing, and if you don't know what that means, you should use main.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Specifically: http://faq.cprogramming.com/cgi-bin/...&id=1043284392

    Note that double semicolons are entirely unnecessary. And <vector> and <string> are too, but let's assume you're going to use them later on . . . .
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginner Needs help in Dev-C++
    By Korrupt Lawz in forum C++ Programming
    Replies: 20
    Last Post: 09-28-2010, 01:17 AM
  2. GradeInfo
    By kirksson in forum C Programming
    Replies: 23
    Last Post: 07-16-2008, 03:27 PM
  3. command line arguments
    By vurentjie in forum C Programming
    Replies: 3
    Last Post: 06-22-2008, 06:46 AM
  4. NULL arguments in a shell program
    By gregulator in forum C Programming
    Replies: 4
    Last Post: 04-15-2004, 10:48 AM
  5. registry, services & command line arguments.. ?
    By BrianK in forum Windows Programming
    Replies: 3
    Last Post: 03-04-2003, 02:11 PM