Thread: command line arguments

  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    30

    command line arguments

    if "fcfs characters.txt" is entered in the command line i have infile.open(argv[2]) to open the file which works correctly but how do i put argv[1] in an if statement? like
    Code:
    if (argv[1] =="fcfs"){do something}
    this line compiles but doesnt do what i tell it to. how do i fix this. What data type is read in from the command line? string? c style string?

  2. #2
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    You can do one of to things. I personally would use the first one.
    Code:
    std::string firstArgument = argv[1];
    
    if(firstArgument == "fcfs"){//do something}
    or
    Code:
    if(strcmp(argv[1], "fcfs") == 0){//do something}
    Woop?

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