【发布时间】:2020-12-01 02:53:43
【问题描述】:
这是我使用 vcvarsall 运行的一段代码,vcvarsall 是 Microsoft Visual Studio 中的一个工具。
Running = true;
while (Running);
{
MSG Message;
BOOL MessageResult = GetMessageA(&Message, 0, 0, 0);
if (MessageResult > 0)
{
TranslateMessage(&Message);
DispatchMessage(&Message);
}
else
{
break;
}
}
我从命令行收到此错误:
错误 C2043:非法中断
我做了一些研究,从 MSDN 中发现,
A break is legal only within a do, for, while, or switch statement.
那么我该如何解决这个错误呢?从我发现的其他 C++ 文档和示例中,这是合法的。这是特定于在 Visual Studio 中运行的 C++ 代码的问题吗?谢谢!
【问题讨论】:
-
去掉
while (Running)之后的;。 -
谢谢!案子解决了!原来问题不那么复杂,现在编译成功了!
-
宋元瑶评论详解:
while (Running);相当于while (Running) { }。然后,其余代码在(空)循环外部/之后执行。
标签: c++ visual-studio loops compiler-errors break