范围解析运算符之前/之后的空格 [英] Space(s) before/after the scope resolution operator

查看:126
本文介绍了范围解析运算符之前/之后的空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C ++语言中,什么规则允许在范围解析运算符::之前和之后出现空格?

What rule in the C++ language allows spaces to appear before of after the scope resolution operator :: ?

即以下编译时不会发出警告:

#include <string>
#include <iostream>

int main ()
{
    std::    string s = "Hello";
    std::    cout << s << std     ::endl;
}

推荐答案

通常,您可以在标记之间放置尽可能多的空间.在某些情况下,空格是必需的(例如,分隔标识符);在其他情况下,它是可选的(例如,在标识符和运算符之间).

In general, you can put as much space as you like between tokens. In some cases, space is necessary (e.g. to separate identifiers); in others, it's optional (e.g. between identifiers and operators).

这在C ++ 11 2.7中进行了描述:

This is described in C++11 2.7:

空白, 如前所述,水平和垂直选项卡,换行符,换页符和注释(统称为空白") 下面的内容将被忽略,除非它们用于分隔令牌. [注意:需要一些空格来分隔其他相邻的标识符,关键字,数字文字和包含字母的替代标记 人物. — 尾注]

Blanks, horizontal and vertical tabs, newlines, formfeeds, and comments (collectively, "white space"), as described below, are ignored except as they serve to separate tokens. [ Note: Some white space is required to separate otherwise adjacent identifiers, keywords, numeric literals, and alternative tokens containing alphabetic characters. — end note ]

这篇关于范围解析运算符之前/之后的空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆