-4

I am using VS-2010. I am passing a vector of string to a function and this function is intend to download images from a list of urls which stored in a vector of strings

void fun::update(vector<std::string>& list_url)
{
  vector<std::string> res ;
    HRESULT hr;
    for(int i=0;i<(unsigned int)list_url.size();i++)
    {  
        res.push_back(list_url[i].substr( list_url[i].find_last_of("/") + 1 ));

    LPCTSTR Url = _T(list_url[i]);
    LPCTSTR File = _T(res[i]);

    hr = URLDownloadToFile(0, Url,File , 0, 0);
    }
}

but this function is showing error that

fun.cpp(29): error C2065: 'Llist_url' : undeclared identifier 1>fun.cpp(30): error C2065: 'Lres' : undeclared identifier

andrewsi
  • 10,807
  • 132
  • 35
  • 51
  • 1
    don't use `_T` for variables. – wimh Nov 29 '14 at 22:00
  • and next time, please mark the lines with errors. Difficult to guess where line 29 and 30 are. – wimh Nov 29 '14 at 22:02
  • i tried it already but it's showing error like : error C2440: 'initializing' : cannot convert from 'std::basic_string<_Elem,_Traits,_Ax>' to 'LPCTSTR' – user3749512 Nov 29 '14 at 22:03
  • sure i will try to do my best to make the error easily visible – user3749512 Nov 29 '14 at 22:04
  • [use the `c_str()` function](http://en.cppreference.com/w/cpp/string/basic_string/c_str) to get a `const char *`. depending on your compiler settings, it is also possible you need to use `wstring` – wimh Nov 29 '14 at 22:08
  • i tried it by using c_str() but the again error is there: error C2440: 'initializing' : cannot convert from 'const char *' to 'LPCTSTR' – user3749512 Nov 29 '14 at 22:11
  • possible duplicate of [How to convert std::string to LPCSTR?](http://stackoverflow.com/questions/1200188/how-to-convert-stdstring-to-lpcstr) – Crowman Nov 29 '14 at 22:57

1 Answers1

2

_T is meant to be used on string literals (e.g. _T("test")).

Karoly Horvath
  • 94,607
  • 11
  • 117
  • 176
  • thank you for your reply but i already tried it and it showing error: error C2440: 'initializing' : cannot convert from 'std::basic_string<_Elem,_Traits,_Ax>' to 'LPCTSTR' – user3749512 Nov 29 '14 at 22:07