Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/129.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ decltype未在此作用域中声明_C++_Decltype - Fatal编程技术网

C++ decltype未在此作用域中声明

C++ decltype未在此作用域中声明,c++,decltype,C++,Decltype,我正在尝试制作一个程序来读取字符串并告诉我其中有多少标点符号。然而,当我试图编译它时,它给出了 错误“'decltype'未在此范围内声明”。我刚刚开始 C++在过去的一个月,对它的概念是新的。 < >我使用DEV C++ 5.11作为代码的IDE。代码来自于书。 C++入门第五版第92页< /P> #include<iostream> #include<cctype> #include<string> using namespace std; int m

我正在尝试制作一个程序来读取字符串并告诉我其中有多少标点符号。然而,当我试图编译它时,它给出了 错误“'decltype'未在此范围内声明”。我刚刚开始 C++在过去的一个月,对它的概念是新的。 < >我使用DEV C++ 5.11作为代码的IDE。代码来自于书。 C++入门第五版第92页< /P>
#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'.
#包括
#包括
#包括
使用名称空间std;
int main(){
字符串s(“你好,世界!!!”;
decltype(s.size()punct_cnt=0;
//计算s中标点符号的数量
for(auto c:s)//对于s中的每个字符
if(ispunct(c))//如果字符是标点符号
++点状;

coutdecltype仅在C++11中引入,可能DevC++没有指示编译器使用C++11模式。在编译器选项中,指示DevC++传递以下命令行标志:

-std=c++11

decltype仅在C++11中引入,DevC++可能没有指示编译器使用C++11模式。在编译器选项中,指示DevC++传递以下命令行标志:

-std=c++11

那是什么疯狂的格式?你错过了一个括号:
decltype(s.size())点头是0,这是你的问题吗?为什么你使用DEVC++?简单地说,在IDENE上工作得很好:什么是C++最好的IDE?不要为它道歉,解决它!你在请求我们的空闲时间来帮助你解决问题,所以至少让你的代码看起来很好。什么是疯狂的格式?你错过了一个支架:<代码>CyType(S.siZe)(0);这是你的问题吗?为什么你使用DEVC++?简单地说,唐。在IDENE上工作得很好:C++最好的IDE是什么?不要为它道歉,解决它!你要我们的空闲时间来帮助你解决问题,所以至少让你的代码看起来很好。