Reputation: 13
I am trying to make a program that reads strings and tells me how many punctuation marks are in it. However, when I try to compile it, it gives the error, "'decltype' was not declared in this scope'. I have just started c++ in the last month and am new to its concepts.
I'm using Dev C++ 5.11 as the IDE for the code. The code is from the book c++ Primer fifth edition on page 92
#include<iostream>
#include<cctype>
#include<string>
using namespace std;
int main() {
string s("Hello World!!!");
decltype(s.size() punct_cnt = 0;
// count the number of punctuation characters in s
for (auto c : s) // for every char in s
if (ispunct(c)) // if the character is punctuation
++punct_cnt;
cout << punct_cnt << " punctuation characters in " << s << endl;
}
I expect it to give the output 3, but it gives the error message, "'decltype' was not declared in this scope'.
Upvotes: 0
Views: 812
Reputation: 41271
decltype was only introduced in C++11, and presumably DevC++ is not instructing the compiler to use c++11 mode. In your compiler options, instruct DevC++ to pass the following command-line flag:
-std=c++11
Upvotes: 3