string str = "abcdef";
cout << str.length() << endl; //6
cout << str.length() - 7 << endl; //4294967295
我不明白为什么 str.length() - 7 返回 4294967295 而不是 -1。
你能帮我解释一下吗?
最佳答案
str.length()
返回一个未签名的 size_t
。这个未签名的结果环绕,这就是为什么你得到 4294967295 而不是 -1。
关于c++ - string::length 返回错误值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46137336/