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

2023-05-16

在用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);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

VS中报错IntelliSense: argument of type "void *" is incompatible with parameter of type "const char *" 的相关文章

随机推荐