如何在windows中从c++程序打开url

How to open a url from a c++ program in windows?

本文关键字:程序 url c++ 中从 windows      更新时间:2023-10-16

我想让我的c++代码打开一个url。然而,所有在线线程都在使用已指定url的ShellExecute。我的代码要求用户输入url,然后程序必须在浏览器中打开它,因此url是字符串的形式。感谢。

我相信这对你来说很有用,当然,如果你使用的是Windows:

    std::cout<<"Enter the link: ";
    std::string link;
    std::cin>>link;
    ShellExecute(NULL, "open", link.c_str(), NULL, NULL, SW_SHOWNORMAL);

像这样:

std::string myUrl;
std::cin >> myUrl;
system(std::string("start " + myUrl).c_str());

?