/google.cpp Secret
Last active
January 12, 2024 04:02
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
can you explain line 21 and 22, please ?
I mean like what is the point of writing append
?
can you explain line 21 and 22, please ?
I mean like what is the point of writing append?
is this platform independent ?
@shyed2001 no
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
Thanks!
I didn't how to open a Url link with cpp.