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

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

问题描述

如何从C ++程序中打开URL?

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

在ruby中,您可以做到

In ruby you can do

%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 ++启动网络浏览器,可以在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");

通过将< mybrowser> 替换为您要启动的浏览器。

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

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

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