Skip to content

Instantly share code, notes, and snippets.

@rodrigoalvesvieira
Last active January 12, 2024 04:02
  • Star 8 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
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;
}
@ferVargasB
Copy link

Thanks!
I didn't how to open a Url link with cpp.

@yaraxxx
Copy link

yaraxxx commented Feb 28, 2019

can you explain line 21 and 22, please ?
I mean like what is the point of writing append?

@ChristianTucker
Copy link

can you explain line 21 and 22, please ?
I mean like what is the point of writing append?

http://www.cplusplus.com/reference/string/string/append/

@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