从C + + code。打开网址 [英] Open URL from C++ code

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

问题描述

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

在Ruby中,你可以做

 %×(打开https://google.com)

什么是C ++中的相同呢?我在想,如果有一个独立于平台的解决方案。但是,如果没有,我想了Unix / Mac的好:)

下面是我的code:

 的#include<&stdio.h中GT;
#包括LT&;&string.h中GT;
#包括LT&;&的fstream GT;INT主(INT ARGC,CHAR *的argv [])
{
    字符的URL [1000] =htt​​ps://www.google.com;    的std :: fstream的FS;
    fs.open(URL);
    fs.close();    返回0;
}


解决方案

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

修改:如果这是有关从C ++的Web浏览器,可以在POSIX系统调用与系统 shell命令:

 系统(< mybrowser> http://google.com);

通过替换< mybrowser方式>您要启动浏览器

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

In ruby you can do

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

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 :)

Here's my code:

#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;
}

解决方案

Use libcurl, here is a simple example.

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 + + code。打开网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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