Shannon D'souza
Shannon D'souza

Reputation: 23

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

I want my c++ code to open a url.However all the threads online promote using ShellExecute with an already specified url. My code requires the user to input the url and the program must then open it in a browser so the url is in the form of a string. Much Appreciated.

Upvotes: 1

Views: 9832

Answers (2)

bl618515
bl618515

Reputation: 107

I believe this should to the trick for you, of course, if you are using Windows:

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

Upvotes: 3

vincentp
vincentp

Reputation: 1433

Something like that :

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

?

Upvotes: 2

Related Questions