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();
4

1 回答 1

3

几个问题。一,您的 else 缺少大括号,二您试图c_str在本机类型(char 数组)上使用成员函数。

我不确定您要做什么(可能使用std::string,但这不能很好地使用sprintf),但是如果您想使用,std::string那么您应该使用它std::stringstream来模拟sprintf正在做的事情,或者只是使用它的构造函数之一来构造它。

于 2013-07-19T07:14:05.910 回答