C++ 关键字: goto
来自 cppreference.com
[编辑] 用法
- goto 语句:作为语句的声明
[编辑] 示例
运行此代码
#include <cassert> #include <string> [[nodiscard]] auto get_first_line(const std::string& string) { std::string first_line{}; for (const auto character : string) switch (character) { case '\n': goto past_for; // breaks from 'range-for loop' default: first_line += character; break; } past_for: return first_line; } int main() { assert(get_first_line("Hello\nworld!") == "Hello"); }
[编辑] 另请参阅
|
(自 C++17 起) |
|
(自 C++23 起) |
(自 C++20 起) |