我安装了Clang 3.4,并测试了用于字符串字面量 ""s 的后缀运算符。
#include <string>
//1. using namespace std; // without compile error.
//2. using std::operator ""s; // or without it compile error, too.
// for success compiles, need 1. or 2. line.
int main()
{
auto s = "hello world"s;
}
如果我注释掉1和2,就会出现编译错误。但我知道在大型项目中,1-方法很糟糕,2-方法很奇怪。
问:我能否在不编写 using namespace std
和 using std :: operator""s
的情况下使用运算符“”s吗?
using
来使字面量后缀生效吗?太难以想象了。 - Lightness Races in Orbitusing namespace std::literals::string_literals;
(例如在使用它们的函数内部) 。 - dypusing namespace std::literals
也可以起作用。 - Howard Hinnant