没有名为'的成员;数组';在命名空间中';std&x27; 我现在正在学习C++,我得到了一些奇怪的错误。
代码如下:没有名为'的成员;数组';在命名空间中';std&x27; 我现在正在学习C++,我得到了一些奇怪的错误。,c++,visual-studio-code,syntax-error,ubuntu-16.04,C++,Visual Studio Code,Syntax Error,Ubuntu 16.04,代码如下: #include <iostream> #include <array> using std::cout; using std::endl; using std::ostream; using std::array; template <typename T, size_t dim> ostream& operator<<(ostream& os, const array<T,dim>& a) {
#include <iostream>
#include <array>
using std::cout;
using std::endl;
using std::ostream;
using std::array;
template <typename T, size_t dim>
ostream& operator<<(ostream& os, const array<T,dim>& a) {
os << "[ ";
for (auto n : a)
os << n << " ";
os << "]";
return os;
}
int main()
{
cout << endl << "--- " << __FILE__ << " ---" << endl << endl;
array<int,3> a1 { 2,3,5 }; // (A)
array<int,0> a2 { }; // (B)
array<int,2> a3 { 1 }; // (C)
// array<int> x1 { 1, 2, 3 }; // (D)
// array<int,3> x2 { 1,2,3,4 };
array<int,3> a4 = { 1,2,3 }; // (E)
array<int,3> a5 { { 4,5,6 } }; // (F)
cout << "01| a1=" << a1 << endl;
cout << "02| a2=" << a2 << endl;
cout << "03| a3=" << a3 << endl;
cout << "04| a4=" << a4 << endl;
cout << "05| a5=" << a5 << endl;
cout << endl << "--- " << __FILE__ << " ---" << endl << endl;
return 0;
}
#包括
#包括
使用std::cout;
使用std::endl;
使用std::ostream;
使用std::数组;
模板
ostream&operator您是否已将VSC配置为理解C++17?将-std=C++17
传递给编译器以启用C++17。阅读手册“man g++”或@JesperJuhl,它已经在makefile中。如果它编译了,它只是一个警告…@MatthieuBrucher我只是在谷歌上搜索了一下,发现了一个c_cpp_properties.json文件。我想这可能是很重要的“编译器路径”:“/usr/bin/clang”、“cStandard”:“c11”、“cppStandard”:“c++17”、“intelliSenseMode”:“clang-x64”在哪里可以配置VSC来理解c++17?
# compiler settings
CXX = g++-7
# CXX = clang++
CXXFLAGS = -ansi -pedantic -Wall -Wextra -Wconversion -pthread -std=c++17
LDFLAGS = -lm
# collect files
CXXEXAMPLES = $(shell find . -name '*.cpp' -print -type f)
CXXTARGETS = $(foreach file, $(CXXEXAMPLES), ./out/$(file:.cpp=.out))
# build them all
all: $(CXXTARGETS)
out/%.out: %.cpp
$(CXX) $(CXXFLAGS) $< $(LDFLAGS) -o $@
clean:
rm out/*