C++ std::size()在C++;17
我对std::大小感到困惑。我做了一些人们说的事情,确保C++ std::size()在C++;17,c++,c++17,C++,C++17,我对std::大小感到困惑。我做了一些人们说的事情,确保#包括,并使用C++17作为cpp标准。但是编译器仍然说“size不是std的成员”。 以下是一个例子: int array[] = {1, 2, 3, 4, 5}; std::cout<<std::size(array); 我的g++--version:“g++.exe(i686-posix-dwarf-rev0,由MinGW-W64项目构建)8.1.0” 当我在终端中使用g++-std=c++17进行编译时,它工作正常。但
#包括,并使用C++17作为cpp标准。但是编译器仍然说“size不是std的成员”。
以下是一个例子:
int array[] = {1, 2, 3, 4, 5};
std::cout<<std::size(array);
我的g++--version
:“g++.exe(i686-posix-dwarf-rev0,由MinGW-W64项目构建)8.1.0”
当我在终端中使用g++-std=c++17
进行编译时,它工作正常。但是直接使用VS代码“运行构建任务”是行不通的
我的tasks.json
:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "g++.exe build active file",
"command": "D:\\software\\mingw32\\bin\\g++.exe",
"args": [
// "-std=c++17",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "D:\\software\\mingw32\\bin"
},
"problemMatcher": [
"$gcc"
],
"group": "build"
}, //why there are two blocks? I modified tasks.json it works well.
{
"type": "shell",
"label": "g++.exe build active file",
"command": "D:\\software\\mingw32\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "D:\\software\\mingw32\\bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
std::size()
可用
尝试为编译器启用-std=c++17
(默认情况下,您的GCC版本可能不支持c++17。要启用c++17支持,请将命令行参数-std=c++17
添加到g++命令行)
另外,对于GCC中的C++17支持,您可以参考
此外,请仔细检查源文件是否包含#include
(我知道你说过你已经检查过了,但仔细检查总是好的),可以直接检查,也可以通过#包含以下任何标题间接检查:
<array>
<deque>
<forward_list>
<list>
<map>
<regex>
<set>
<string>
<string_view>
<unordered_map>
<unordered_set>
<vector>
您的编译器不支持C++17。或者您没有使用该选项启用C++17支持。如何编译?您设置了编译器标志吗-std=c++17
当然是c++17的一部分。我在我自己的代码中使用它来处理clang 7、GCC 9和MSVC 2019。g++--version
为您提供了什么输出?谢谢,但我确定不包括任何其他头文件,因为这只是一个文件程序。
<array>
<deque>
<forward_list>
<list>
<map>
<regex>
<set>
<string>
<string_view>
<unordered_map>
<unordered_set>
<vector>