Downloading from specified URL

This is a discussion on Downloading from specified URL within the C++ Programming forums, part of the General Programming Boards category; Hi everyone, I am trying to make a program which will allow you to input a number and then it ...

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    128

    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,668
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Feb 2010
    Posts
    128
    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
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,651
    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: 11
    Last Post: 02-17-2010, 11:36 PM
  2. How to make URL connection and read from URL
    By abmirayo in forum C Programming
    Replies: 3
    Last Post: 02-15-2010, 03: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21