Thread: Downloading from specified URL

  1. #1
    george7378
    Guest

    Downloading from specified URL

    Hi everyone,

    I am trying to make a program which will allow you to input a number and then it will add that number into the URL. Here is some of the code:

    Code:
    HRESULT hr = URLDownloadToFile( NULL, L"http://www.my-site.com/number.png", L"image.bmp", 0, NULL );
    Basically, I am allowing the user to store a number in a variable, and then the program will add that number onto the end of the URL so that an image with the name 'number.png' (where 'number' is the value they enter) will download. Long story short - how do you allow the user to change the URL that it downloads from?

    Thanks.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    http://msdn.microsoft.com/en-us/libr...=vs.80%29.aspx

    Like
    Code:
    wstringstream fn;
    int number = 42;
    fn << L"http://www.my-site.com/" << number << ".png";
    HRESULT hr = URLDownloadToFile( NULL, fn.c_str(), L"image.bmp", 0, NULL );
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    george7378
    Guest
    Thanks for the response - I tried to change it to that, but I get this:

    Code:
    error C2039: 'c_str' : is not a member of 'std::basic_stringstream<_Elem,_Traits,_Alloc>'
            with
            [
                _Elem=wchar_t,
                _Traits=std::char_traits<wchar_t>,
                _Alloc=std::allocator<wchar_t>
            ]
    Any ideas what I'm doing wrong? Thanks!

  4. #4
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    Try
    Code:
    HRESULT hr = URLDownloadToFile( NULL, fn.str().c_str(), L"image.bmp", 0, NULL );
    the str() retrieves the C++ string from the stringstream, the c_str() converts that C++ string to a const char * -- a const C-string -- which is what URLDownloadToFile wants.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. URL splitter
    By monki000 in forum C Programming
    Replies: 10
    Last Post: 02-18-2010, 12:36 AM
  2. How to make URL connection and read from URL
    By abmirayo in forum C Programming
    Replies: 3
    Last Post: 02-15-2010, 04:59 PM
  3. URL escape issue
    By George2 in forum C# Programming
    Replies: 2
    Last Post: 08-12-2008, 11:45 AM
  4. Interpreter.c
    By moussa in forum C Programming
    Replies: 4
    Last Post: 05-28-2008, 05:59 PM
  5. Replies: 1
    Last Post: 07-02-2007, 09:22 AM