gpt4 book ai didi

c++ - 'std:;' 在 C++ 中会做什么?

转载 作者:IT老高 更新时间:2023-10-28 11:58:32 25 4
gpt4 key购买 nike

我最近在修改一些代码,并在函数内的一行中发现了一个预先存在的错误:

std:;string x = y;

此代码仍可编译,并且一直按预期工作。

字符串定义有效,因为这个文件是 using namespace std;,所以 std:: 一开始是不必要的。

问题是,为什么要编译 std:; 以及它在做什么(如果有的话)?

最佳答案

std: 它是一个标签,可用作 goto 的目标。

正如 @Adam Rosenfield 在评论中指出的那样,这是一个合法的标签名称。

C++03 §6.1/1:

Labels have their own name space and do not interfere with other identifiers.

关于c++ - 'std:;' 在 C++ 中会做什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12807115/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com