The error: ‘len’ does not name a type
leads me to believe that you didn't compile in C++11 mode and that it's using the old, C++98 meaning of the keyword auto
.
auto keyword is not deducing type of string
-
02-06-2022 - |
Вопрос
I've this simple code:
#include <string>
#include <iostream>
using namespace std;
int main() {
string s1 = "rohit";
auto len = s1.size();
cout << len;
}
When I compile this code on Ubuntu 12.04, it shows following error:
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;
^
I've got g++ 4.8.1. Is there some changes with the usage of auto
keyword in g++ 4.8.1?
Решение
Не связан с StackOverflow