[英]Warning: truncation from int to char, when using string::find_first_not_of
We try to clean up our project and remove all warnings. 我们尝试清理我们的项目并删除所有警告。 I get warning for this line:
我收到这条线的警告:
if(line.find_first_not_of('\n\t ') != string::npos) {
warning C4305: 'argument' : truncation from 'int' to 'char'
I am not sure what to do... Both values are size_t, not sure why it complains. 我不知道该怎么做......这两个值都是size_t,不确定为什么会抱怨。
The warning is misleading. 该警告具有误导性。 It should rather warn about multi-character to char conversion, as you're using
'\\n\\t'
(which is multi-character) instead of "\\n\\t"
(which is a string). 它应该警告多字符到字符转换,因为你使用
'\\n\\t'
(多字符)而不是"\\n\\t"
(这是一个字符串)。
Anyway, you need to use double quotes here: 无论如何,你需要在这里使用双引号 :
if(line.find_first_not_of("\n\t ") != string::npos)
Hope that helps. 希望有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.