user2381422
user2381422

Reputation: 5805

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.

Upvotes: 3

Views: 2532

Answers (1)

Sarfaraz Nawaz
Sarfaraz Nawaz

Reputation: 361254

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).

Anyway, you need to use double quotes here:

 if(line.find_first_not_of("\n\t ") != string::npos)

Hope that helps.

Upvotes: 13

Related Questions