我有一个简单的代码:
#include <string>
#include <iostream>
using namespace std;
int main() {
string s1 = "rohit";
auto len = s1.size();
cout << len;
}
当我在Ubuntu 12.04上编译这段代码时,它显示了以下错误:
test.cc: In function ‘int main()’:
test.cc:8:10: error: ‘len’ does not name a type
auto len = s1.size();
^
test.cc:10:13: error: ‘len’ was not declared in this scope
cout << len;
^
我有g++4.8.1。在g++4.8.1中auto
关键字的使用有什么变化吗?
error: ‘len’ does not name a type
让我相信你不是在C++11模式下编译的,它使用了关键字auto
的旧的C++98含义。