Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Reading input from command line C++, instead of sscanf

Options
  • 07-03-2013 11:05am
    #1
    Closed Accounts Posts: 46


    Hey,

    Last semester we studied C Programming and now we are studying C++.

    We are doing a program that compares two files, the two files are specified on the command line, I completed this program fine with C.

    In C Programming, I was able to read the file names in with sscanf using the following code:
    int main(int argc, char *argv[])
    {
      char fname1[20], fname2[20];
    
     //scan the second argument entered by the user, store it in fname1
    
     sscanf(argv[1], "%19s", fname1); 
     sscanf(argv[2], "%19s", fname2); // scan third argument(other file)
    
    }
    
    

    I am not sure how best to implement the above step in C++, looking online there are some suggestions of using stringstream..but I can`t figure it out.

    Any ideas you may have would be a great help.. Thanks :)


Comments

Advertisement