list5-2.cpp

来自「这是c++编程方面的名著的例子代码」· C++ 代码 · 共 31 行

CPP
31
字号
// Listing 5-2
// Demonstates the use of  execl
// one of the family of exec( ) functions
// used to spawn child processes
// accepts a sequence of four integers that will be
// passed to the program from list5-1

#include <iostream.h>
#include <strstrea.h>
#include <stdlib.h>
#include <process.h>

void main(int argc, char *argv[])
{


   if(argc == 5){
      char Argument[81] = "";
      strstream Buffer;
      Buffer << (atol(argv[1]) * 2) << " ";
      Buffer << (atol(argv[2]) * 3) << " ";
      Buffer << (atol(argv[3])+ atol(argv[1])) << " ";
      Buffer << atol(argv[4]) << ends;
      Buffer.getline(Argument,80,'\0');
      cout << "Result " << Argument << endl;
      execl("list5-1.exe","List5-1.exe",Argument,NULL);
   }

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?