simple site opener

I saw very complicated programs on net to open a site but i want to make a simple c++ program to open a site.

Here is my code but it does not open the site.Also how do i make it so it opens in a particular browser only?

1
2
3
4
5
6
7
8
  #include<iostream>
#include<fstream>
using namespace std;
int main()
{
   fstream fs;
   fs.open("www.google.com");
}
See: std::system() http://en.cppreference.com/w/cpp/utility/program/system

For example, on windows:
1
2
3
4
5
6
7
8
9
// https://technet.microsoft.com/en-us/library/bb491005.aspx
// open this page in chrome
std::system( "start chrome http://www.cplusplus.com/forum/beginner/227697/" ) ;

// open this page in the default browser
std::system( "start http://www.cplusplus.com/forum/beginner/227697/" ) ;

// If the program is running with elevated privileges, use the /I option. For example:
std::system( "start /I http://www.cplusplus.com/forum/beginner/227697/" ) ;

Last edited on
This is actually something fairly easy to do cross-platform:

1
2
3
4
5
6
7
#ifndef INVOKE_BROWSER_HPP
#define INVOKE_BROWSER_HPP

#include <string>
int invoke_browser( const std::string& URL );

#endif 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <cstdlib>
#include <string>

#ifdef __APPLE__
#include <TargetConditionals.h>
#endif

int invoke_browser( const std::string& URL )
{
  #ifdef _WIN32
  return std::system( ("start \"\" " + URL).c_str() );

  #elif defined(__APPLE__) && TARGET_OS_MAC
  return std::system( ("open " + URL + " &").c_str() );

  #else
  return std::system( ("xdg-open " + URL + " &").c_str() );
  #endif
}
thanks guys.
Registered users can post here. Sign in or register to post.