Thread: Downloading from specified URL

  1. #1
    Registered User
    Join Date
    Feb 2010

    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:

    HRESULT hr = URLDownloadToFile( NULL, L"", 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?


  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe

    wstringstream fn;
    int number = 42;
    fn << L"" << 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
    Registered User
    Join Date
    Feb 2010
    Thanks for the response - I tried to change it to that, but I get this:

    error C2039: 'c_str' : is not a member of 'std::basic_stringstream<_Elem,_Traits,_Alloc>'
    Any ideas what I'm doing wrong? Thanks!

  4. #4
    Join Date
    Dec 2007
    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: 11
    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