Skip to content

Instantly share code, notes, and snippets.

@rodrigoalvesvieira
Last active January 12, 2024 04:02
Show Gist options
  • Save rodrigoalvesvieira/662e400f34dd9de38176 to your computer and use it in GitHub Desktop.
Save rodrigoalvesvieira/662e400f34dd9de38176 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string>
using namespace std;
// Google Search C++ program
// g++ -o google google.cpp
// ./google rodrigo alves github | xargs open
// sudo mv google /usr/bin
int main (int argc, char *argv[])
{
int i = 1;
string url = "https://www.google.com/search?q=";
for (; i < argc; i++) {
url = url + string(argv[i]);
if (i != argc-1) url = url + string("+");
}
cout << url << endl;
string op = string("open ").append(url);
system(op.c_str());
return 0;
}
@shyed2001
Copy link

is this platform independent ?

@charleywright
Copy link

@Renardjojo
Copy link

Here is a cross platform example to open URL

#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
#define SystemOpenURL(url) system("start " url);
#elif __APPLE__
#define SystemOpenURL(url) system("open " url);
#elif __linux__
#define SystemOpenURL(url) system("xdg-open" url);
#else
#error "Unknown compiler"
#endif

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment