在启动时为应用程序提供一些数据

Avi*_*der 2 c++ launch

我正在尝试创建一个可以从另一个程序接收一些数据的应用程序.例如:

Start_App.exe calls Main_App.exe and gives it the current date, all at the same time
(while launching it)

Main_App.exe outputs the date on its console
Run Code Online (Sandbox Code Playgroud)

如果没有Start_App传递的数据,其他程序将无法正常工作或将执行其他操作.我一直在寻找,但似乎我错过了技术名称......

ben*_*enj 6

您可能希望使用命令行参数.
它们通过在程序名称之后直接写出来,以空格分隔来传递.

像这样:

#include <iostream>

int main(int argc, char *argv[])
{
    using namespace std;

    cout << "There are " << argc << " arguments:" << endl;

    // Loop through each argument and print its number and value
    for (int nArg=0; nArg < argc; nArg++)
        cout << nArg << " " << argv[nArg] << endl;

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

argc是程序收到的参数数量.
*argv[]是一个字符串数组,每个参数一个.

如果你这样调用程序:

Program.exe arg1 arg2 arg3
Run Code Online (Sandbox Code Playgroud)

它给你:

There are 3 arguments:
0 arg1
1 arg2
2 arg3
Run Code Online (Sandbox Code Playgroud)