[英]Argument of type “const char **” is incompatible with parameter of type “const char *”
[英]Argument of type “const char *” is incompatible with parameter of type “char *”
我正在嘗試加入“ip-api.com/json/”並聲明char“ip_address”,但“ip-api.com/json/”用紅色下划線標出:
argument of type "const char *" is incompatible with parameter of type "char *"
如何做呢?
TCHAR path[_MAX_PATH];
_tcscpy(path, ip_address);
_tcscat("ip-api.com/json/", ip_address);
在這個電話中
_tcscat("ip-api.com/json/", ip_address);
您正在嘗試修改字符串文字。
C ++中的字符串文字具有常量字符數組的類型。 所以轉換為指針,他們有類型const char *
。
您可能無法更改字符串文字。 任何更改字符串文字的嘗試都會導致未定義的行為。
此外,您必須保留足夠大的內存,以便將ip_address
指向的字符串附加到字符數組中的另一個字符串。
例如
char address[_MAX_PATH] = "ip-api.com/json/";
_tcscat( address, ip_address);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.