Gcc “注释掉”后出现的问题;使用名称空间std&引用; 我是C++新手,我读到“使用命名空间STD”被认为是不好的练习。我使用以下代码测试编译器是否符合c++14: #包括 #包括 使用名称空间std; 自动添加([](自动a,自动b){返回a+b;}); auto main()->int{cout

Gcc “注释掉”后出现的问题;使用名称空间std&引用; 我是C++新手,我读到“使用命名空间STD”被认为是不好的练习。我使用以下代码测试编译器是否符合c++14: #包括 #包括 使用名称空间std; 自动添加([](自动a,自动b){返回a+b;}); auto main()->int{cout,gcc,namespaces,c++14,using-directives,return-type-deduction,Gcc,Namespaces,C++14,Using Directives,Return Type Deduction,clang++给出了一条很好的错误消息: error: no matching literal operator for call to 'operator""s' with arguments of types 'const char *' and 'unsigned long', and no matching literal operator template auto main() -> int { std::cout << add("We have C", "++14

clang++
给出了一条很好的错误消息:

error: no matching literal operator for call to 'operator""s' with arguments of types 'const char *' and 'unsigned long', and no matching literal operator template
auto main() -> int { std::cout << add("We have C", "++14!"s); }
                                                          ^
或使用声明使用:

int main() {
  using std::operator""s;
  std::cout << add("We have C", "++14!"s);
}
intmain(){
使用std::运算符“”s;

std::cout这是字符串文本上的
s
后缀,而不是
cout
使用std::operator“s
@Ryan
使用名称空间std::string\u literals;
是更传统的方法。首选
使用名称空间std::string\u literals
int main() {
  std::cout << add("We have C", std::operator""s("++14!", 5));
  // Note the length of the raw character array literal is required
}
int main() {
  using std::operator""s;
  std::cout << add("We have C", "++14!"s);
}