why 2 different outputs?

Why does the program print 2 different values?


[1]


  [1]: http://ideone.com/QOuywW

It’s happening because of type conversion. npos is a static member constant value which takes the greatest possible value of size_t. If you know about size_t that it’s unsigned integral type and by default it’s value is assigned as -1.

But as i said it’s unsigned type so in the line "int x… " type conversion takes place and print the default value of -1. but if you output this value of npos by cout<< then it will be treated as unsigned and print the largest value of integral type.

The right way to get same output is HERE

I think you will find your answer here