小编Dra*_*els的帖子

在 C++ 中使用 istringstream

我有一些代码使用 fork、execlp 和 wait 来创建两个进程。目标是能够重复打印提示并让用户输入命令,该命令最多包含 4 个参数/选项。

int main()
{
     string command, argument;
     istringstream iss(argument);

  do
  {
  //prompt user for command to run
  cout << "Enter command: ";
  cin >> command >> argument;

  int pid, rs, status;
 
  //fork will make 2 processes
  pid = fork();
  if(pid == -1) { perror("fork"); exit(EXIT_FAILURE); }

if(pid == 0) {
//Child process: exec to command with argument

//C_str to get the character string of a string
rs = execlp(command.c_str(), command.c_str(), argument.c_str(), (char*) NULL);
. …
Run Code Online (Sandbox Code Playgroud)

c++ fork exec wait istringstream

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

c++ ×1

exec ×1

fork ×1

istringstream ×1

wait ×1