小编Agi*_*rro的帖子

C++ 中 string::size() 乘以负整数时的奇怪行为

运行这段代码:

#include <string>
#include <iostream>
using namespace std;
int main() {
    string a = "Hello, world!";
    cout << (-1)*a.size() << endl;
}
Run Code Online (Sandbox Code Playgroud)

我得到:

18446744073709551603
Run Code Online (Sandbox Code Playgroud)

这显然不是我想要的。每当我尝试将 string::size() 乘以负数(但不是正数!)时,都会发生这个恼人的错误。我不明白这里出了什么问题。

c++ stdstring

3
推荐指数
1
解决办法
767
查看次数

标签 统计

c++ ×1

stdstring ×1