Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I open a URL from C++?

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; } 
like image 958
rodrigoalvesvieira Avatar asked Jun 27 '13 16:06

rodrigoalvesvieira


1 Answers

Your question may mean two different things:

1.) Open a web page with a browser.

#include <windows.h> #include <shellapi.h> ... ShellExecute(0, 0, L"http://www.google.com", 0, 0 , SW_SHOW ); 

This should work, it opens the file with the associated program. Should open the browser, which is usually the default web browser.


2.) Get the code of a webpage and you will render it yourself or do some other thing. For this I recommend to read this or/and this.


I hope it's at least a little helpful.

EDIT: Did not notice, what you are asking for UNIX, this only work on Windows.

like image 75
ST3 Avatar answered Sep 27 '22 17:09

ST3