c++ 从命令行获取参数_从命令行获取天气

c++ 从命令行获取参数

There's an awesome script making the rounds on Twitter and I've been as excited as everyone else so I thought I'd show it.  Many of us live eight hours a day within the command line (although I'm not a vim hippie like some of you) so I try to find new ways to accomplish tasks from within iTerm (like getting bitcoin value or stock quotes).  Many of these solutions include using cURL and this awesomeness is no exception!

Twitter上有一个很棒的脚本来回合,我和其他所有人一样兴奋,所以我想展示一下。 我们中的许多人每天都在命令行中生活8个小时(尽管我不像你们中的某些人那样活跃),所以我尝试找到在iTerm内完成任务的新方法(例如获得比特币价值股票报价 )。 这些解决方案中的许多解决方案都包括使用cURL,这一点也不例外!

curl weather

You can get weather information from command line using cURL and wttr.in:

您可以使用cURL和wttr.in从命令行获取天气信息:


# Allow geolocation
curl -4 wttr.in

# Request a city
curl -4 wttr.in/Madison


wttr.in does well to guess location if one isn't provided so in most cases you wont need to provide your city.

wttr.in很容易猜测是否未提供位置,因此在大多数情况下,您不需要提供城市。

There you go, another awesome way to get the information you need from command line!

到这里,从命令行获取所需信息的另一种绝佳方法!

翻译自: https://davidwalsh.name/get-weather-command-line

c++ 从命令行获取参数

C++中,如果你想要通过命令行(Console)获取窗口参数,通常是通过解析命令行参数来实现的。C++标准库中的`<cstdlib>`提供了`atoi`等函数来将字符串参数转换为整型,但对于获取窗口参数,这通常涉及到操作系统特定的API调用。 在Windows系统中,你可以使用`GetCommandLine`函数来获取完整的命令行字符串,然后解析这个字符串来获取特定的窗口参数。以下是一个简单的例子,展示了如何在Windows中获取命令行参数: ```cpp #include <windows.h> #include <iostream> int main(int argc, char* argv[]) { // 检查命令行参数的数量 if (argc > 1) { // 第一个参数是程序名,接下来的参数命令行参数 // 这里我们假设命令行参数的格式为 "/窗口ID=1234" for (int i = 1; i < argc; ++i) { char* cmdLineArg = argv[i]; // 检查参数是否以 "/窗口ID=" 开头 if (strncmp(cmdLineArg, "/窗口ID=", 8) == 0) { // 获取窗口ID参数 char* windowIdStr = cmdLineArg + 8; // 这里假设窗口ID是十进制数 int windowId = atoi(windowIdStr); std::cout << "窗口ID: " << windowId << std::endl; break; } } } else { std::cout << "没有提供窗口ID参数。" << std::endl; } return 0; } ``` 在上面的代码中,程序首先检查命令行参数的数量,然后遍历这些参数。如果某个参数以"/窗口ID="开头,它就假定该参数后面跟着的是窗口ID,并将其从字符串转换为整数。 请注意,上面的代码假设窗口ID是一个十进制数,并且使用了标准的ASCII比较函数`strncmp`。对于窗口ID的获取,你可能还需要调用Windows API(如`FindWindow`)来进一步操作窗口。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值