Thread: Opening URL's from your code

  1. #1
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273

    Opening URL's from your code

    Can this be done? we'll say for example I wanted to go to www.cprogramming.com, can the program bring me to it from inside?

  2. #2
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    Code:
    #include <windows.h>
     
    int main()
    {
        ShellExecute(NULL, "open", "http://www.cprogramming.com",
                     NULL, NULL, SW_SHOWNORMAL);
        return 0;
    }
    I'm sure there is similar for *nix.
    Last edited by SlyMaelstrom; 12-09-2005 at 03:23 PM.
    Sent from my iPadŽ

  3. #3
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    cool!! that works for a hardwared website, but can you do it for a user defined one too?

  4. #4
    ^ Read Backwards^
    Join Date
    Sep 2005
    Location
    Earth
    Posts
    282
    To modify sly's code...very easy.
    Code:
    	string go;
    	cin >> go;
    
        ShellExecute(NULL, "open", go.c_str(),NULL, NULL, SW_SHOWNORMAL);
        return 0;

  5. #5
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    Hmmm, thanks, em, when I do that I get this error:

    U:\countdown.cpp(11) : error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or there is no acceptable conversion)

    here's the code:

    Code:
    #include <stdio.h>
    #include <iostream>
    #include <windows.h>
    using namespace std;
    
    
    int main()
    {
    	
    	string go;
    	cin >> go;
    
        ShellExecute(NULL, "open", go.c_str(),NULL, NULL, SW_SHOWNORMAL);
    
        return 0;
    }

  6. #6
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    Works fine for me.

    By the way don't mix includes like that.

    Code:
    #include <cstdio>
    #include <iostream>
    #include <windows.h>
    Sent from my iPadŽ

  7. #7
    ^ Read Backwards^
    Join Date
    Sep 2005
    Location
    Earth
    Posts
    282
    To use the string type you must also [code[#include <string>[/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Proposal: Code colouring
    By Perspective in forum A Brief History of Cprogramming.com
    Replies: 28
    Last Post: 05-14-2007, 07:23 AM
  2. Replies: 11
    Last Post: 01-10-2007, 06:53 AM
  3. Explain this C code in english
    By soadlink in forum C Programming
    Replies: 16
    Last Post: 08-31-2006, 12:48 AM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Replies: 4
    Last Post: 01-16-2002, 12:04 AM