我试着编译这段代码:-
#include <vector>
using namespace std;
int main() {
vector<int> v(5);
iota(v.begin(), v.end(), 0);
}我用这个命令编译了它:-
D:\workspace\test>nvcc main.cpp --std=c++11(因为没有指定std,我就得到了“标识符iota()未找到”错误)
我得到了一个错误:-
nvcc warning : The -std=c++11 flag is not supported with the configured host compiler. Flag will be ignored.
main.cpp
main.cpp(7): error C3861: 'iota': identifier not found如何指定我希望nvcc使用的C++标准?
另外,分别用g++编译主机代码和用nvcc编译设备代码,然后将对象与nvcc连接起来就不起作用了。我得到了这。
发布于 2018-07-02 11:53:14
不必了。默认情况下,命令行工具nvcc使用微软的cl.exe。如果您的cl.exe被更新了,那么的选项是不可用的。cl.exe自动支持所有最新的C++标准的特性。
但是,在cl.exe中,像iota()这样的一些函数没有在std命名空间中定义。相反,iota()是在数值.h头文件中定义的。因此,要运行该代码,您需要包含上述头文件。最后的代码应该如下所示:
#include <vector>
#include <numeric.h>
using namespace std;
int main() {
vector<int> v(5);
iota(v.begin(), v.end(), 0);
}该代码可由以下命令编译:
nvcc main.cpp发布于 2018-07-02 08:58:12
我认为你需要添加#include <numeric>。在这里输入图像描述
https://stackoverflow.com/questions/51132234
复制相似问题