小编Ale*_*vic的帖子

用 C 创建 CLI 应用程序

我想知道如何用 C 语言制作一个“持续运行”的 CLI 应用程序。我的意思是,例如,我只想打开终端并输入关键字,然后程序中的函数就会执行。就像“ls”是什么一样。当您键入 ls 时,它会列出当前目录的内容。同样,我想制作一个程序,在编译时,如果调用关键字,它会执行特定的内容。我不想使用 ./example 运行可执行文件,而是让命令始终可用。我使用的编译器是 gcc。我已读到需要创建目标文件,但我不知道如何使用它。

谢谢

c

2
推荐指数
1
解决办法
3685
查看次数

Checking for specific command line arguments in C++

I am building a CLI app that should do something similar to this:

./app

Welcome to the app, Type -h or --help to learn more.

./app -h

list of commands:...
Run Code Online (Sandbox Code Playgroud)

Here is the code i am trying to build:

#include <iostream>

using namespace std;

int main(int argc, char** argv)  {

   cout << "Welcome to the app. Type -h or --help to learn more\n";

   if(argv == "-h" || argv == "--help") {
      cout << "List of commands:...";
   }
  return 0;
} …
Run Code Online (Sandbox Code Playgroud)

c++ command-line-arguments

-1
推荐指数
1
解决办法
678
查看次数

标签 统计

c ×1

c++ ×1

command-line-arguments ×1