VS中报错IntelliSense: argument of type "void *" is incompatible with parameter of type "const char *"

在用VS编写C++程序的时候,遇到这样的问题IntelliSense: argument of type “void *” is incompatible with parameter of type “const char *”,但是给的例程确实传入参数就是void *,网上找了很久没发现解决办法。

size_t getcontentlengthfunc(void *ptr, size_t size, size_t nmemb, void *stream)
{	int r;	long len = 0; 
	r = sscanf(ptr, "Content-Length: %ld\n", &len);//这一句的ptr变量报错,sscanf第一个参数是const char *或string类型。
		if (r)		
		*((long *)stream) = len; 	r
		eturn size * nmemb;
}

后面尝试将报错的void*变量ptr加上强制类型转换后就不报错了:

r = sscanf((const char *)ptr, "Content-Length: %ld\n", &len);

你可能感兴趣的:(C++)