C++ 关键词:goto
来自cppreference.com
[编辑]用法
- goto 语句:用作语句的声明
[编辑]示例
运行此代码
#include <cassert>#include <string> [[nodiscard]]auto get_first_line(conststd::string& string){std::string first_line {};for(constauto character : string)switch(character){case'\n':goto past_for;// 打断 '范围 for 循环'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 起) |