0

I'm trying to convert pszOutBuffer which is created below into a const char * So to do this I'm attempting to use sprintf to create a char called buffer and then finally getting the buffer's c_str(). But buffer is thowing the error "Expression must have a class type"

if( !WinHttpReadData( hRequest, (LPVOID)pszOutBuffer,  
    dwSize, &dwDownloaded ) )
    printf( "Error %u in WinHttpReadData.\n", GetLastError( ) );
 else
    printf( "%s", pszOutBuffer );
    char buffer [4096];
    sprintf(buffer,"%s",pszOutBuffer);
    returnval = buffer.c_str();
Cassio Neri
  • 19,583
  • 7
  • 46
  • 68
Kegan Hollern
  • 1
  • 1
  • 1
  • 1

1 Answers1

3

A couple issues. One, you're missing braces on your else, and two you're trying to use c_str member function on a native type (char array).

I'm unsure what you meant to do (probably use std::string, but that wouldn't work very well with sprintf) but if you wanted to use std::string then you should use std::stringstream to emulate what sprintf is doing or just construct it with one of its constructors.

Rapptz
  • 20,807
  • 5
  • 72
  • 86