我对这个简单的问题感到困惑.这是我的代码:
#include <iostream>
#include <string>
int main()
{
std::string str = "bb";
int counter;
for (counter = str.length() - 1; counter >= str.length() - 2; counter--)
{
std::cout << "counter: " << counter << std::endl;
}
}
Run Code Online (Sandbox Code Playgroud)
基本上,它应该只打印两行,然后终止程序,但它保持打印行.事实上,循环不会在counter = -1处停止,这很奇怪!为什么会这样?