简体   繁体   English

strtok 函数 const char 指针错误

[英]strtok function const char pointer error

I keep getting the following Error我不断收到以下错误

passing argument 1 of 'strtok' discards 'const' qualifier from pointer target type [enabled by default]

Through this line通过这条线

for (char *p = strtok(season_info,"\n"); p != NULL; p = strtok(NULL, " "))

ps: season_info is defined like this: const char* season_info ps:season_info 的定义如下: const char* season_info

strtok needs to make changes to your string, so it can't operate on a const char* argument. strtok需要对您的字符串进行更改,因此它无法对const char*参数进行操作。 You'll need to make a copy of that string before sending it to strtok .在将其发送到strtok之前,您需要制作该字符串的副本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM