Senin, 02 Juli 2012

Google Web Search


Quote
This snippet performs a google web search, showing the results in the default webbrowser.



//This snippet performs a google web search, showing the results in the default webbrowser.
#include <iostream>
#include <string>
#include <windows.h>
using namespace std;
//function to obtain the full url of the Google Websearch
string WebSearch(string query) {
  int i=0;
  for(i; i<query.size(); i++) {
  if(query[i]==' ') { //if the query contains a space, replace it with "+"
  query=query.replace(query.find(" ",0), 1, "+"); 
  }
  else if(query[i]=='+') { // if the query contains a "+" replace it with "%2B"
  query=query.replace(query.find("+",0), 1, "%2B");
  }
  }
  string url="http://www.google.com/search?q=";
  url.insert(url.size(), query);
  return url.c_str(); }
//The main program
int main() {   
        string s;
        getline(cin,s);
        s=WebSearch(s);
        ShellExecute(NULL, "open", s.c_str(), NULL, NULL, SW_SHOWNORMAL);
        return 0;
}

Tidak ada komentar:

Posting Komentar