-1

I am writing a program that will recreate the pipe in UNIX. The user enters a command that gets stored in a char array arguments included and in order to execute them I need to call exec but my program is how do I separate the command from the arguments so I can do something like this:

data in char command: ls -l
execvp("ls", <arguments>(in this case -l));
Scholar
  • 293
  • 3
  • 8
  • 16
  • 1
    [How to split a string in C++](http://stackoverflow.com/questions/236129/how-to-split-a-string-in-c) might be helpful – AliciaBytes Nov 05 '13 at 03:20
  • getline always throws errors in my direction, is getline really the only solution? – Scholar Nov 05 '13 at 03:25
  • 1
    Of course not. provided they're just whitespace separated strings you can just use the natural `std::string` extraction operator after loading the C-string into an `std::istringstream` the linked article has *many such examples, and I urge you to review the different options available to you. And if `std::getline` throws errors at you, odds are you didn't setup the stream correctly (it shouldn't be in binary-mode, for example). – WhozCraig Nov 05 '13 at 03:44

1 Answers1

-1

Perhaps you need to use strtok function: http://www.cplusplus.com/reference/cstring/strtok/.

nim
  • 384
  • 2
  • 14
  • Probably your answer is correct, but it doesn't meet StackOverflow requirements about answering. The valid answer should contain code sample not only link to documentation (even if it's more or less official). Please fix it to revert downvotes and/or get more upvotes. – biesior Sep 06 '20 at 11:36