如何从 C++ 打开 URL? [英] How do I open a URL from C++?

查看:25
本文介绍了如何从 C++ 打开 URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从我的 C++ 程序打开 URL?

how can I open a URL from my C++ program?

在红宝石中你可以做到

%x(open https://google.com)

C++ 中的等价物是什么?我想知道是否有独立于平台的解决方案.但如果没有,我更喜欢 Unix/Mac :)

What's the equivalent in C++? I wonder if there's a platform-independent solution. But if there isn't, I'd like the Unix/Mac better :)

这是我的代码:

#include <stdio.h>
#include <string.h>
#include <fstream>

int main (int argc, char *argv[])
{
    char url[1000] = "https://www.google.com";

    std::fstream fs;
    fs.open(url);
    fs.close();

    return 0;
}

推荐答案

使用 libcurl,这里是一个简单的示例.

Use libcurl, here is a simple example.

编辑:如果这是关于从 C++ 启动 Web 浏览器,您可以在 POSIX 系统上使用 system 调用 shell 命令:

EDIT: If this is about starting a web browser from C++, you can invoke a shell command with system on a POSIX system:

system("<mybrowser> http://google.com");

替换为您要启动的浏览器.

By replacing <mybrowser> with the browser you want to launch.

这篇关于如何从 C++ 打开 URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆