[英]Why am I receiving C2440 error for string when trying to open file using <netcdf> library?
I am trying to read a.netCDF file with the library in C++. However, I am getting a C2440 error, telling me that I cannot convert the type of the dataFile to the dataVar.我正在尝试使用 C++ 中的库读取 .netCDF 文件。但是,我收到 C2440 错误,告诉我无法将 dataFile 的类型转换为 dataVar。 Or, at least this is what I think it is telling me because the compiler error seems a little cryptic to read.
或者,至少这是我认为它告诉我的,因为编译器错误读起来似乎有点神秘。
Here is my code:这是我的代码:
//create a test object to open netcdf file
const std::vector<std::string> path = obj.getPaths(); //returns all paths in the netcdf directory
const std::string test = path[0]; //gives me a test path that is element 1 in the path vector
netCDF::NcFile dataFile(test, netCDF::NcFile::read);
netCDF::NcVar dataVar = dataFile.getVars();
error:错误:
Error C2440 'initializing': cannot convert from 'std::multimap<std::string,netCDF::NcVar,std::less<Aws::String>,std::allocator<std::pair<conststd::string,netCDF::NcVar>>>' to 'netCDF::NcVar' count-lightning C:\Users\Corey4005\Desktop\Dev\projects\count-lightning\src\main.cpp 59
What should I do to make this code work?我应该怎么做才能使这段代码工作?
Thanks for the help!谢谢您的帮助!
What I have tried:我试过的:
I tried to open a.netcdf file using the NcFile stream. The NcFile stream takes the following arguments:我尝试使用 NcFile stream 打开.netcdf 文件。NcFile stream 采用以下 arguments:
netCDF::NcFile dataFile(const std::string &filePath, netCDF::NcFile::fileMode fMode);
When I provided a string literal to the filePath argument, I received a C2440 'initializing' error.当我向 filePath 参数提供字符串文字时,我收到了 C2440“初始化”错误。 I am confused because I think I am correctly passing a const string literal to a const string argument.
我很困惑,因为我认为我正确地将 const 字符串文字传递给 const 字符串参数。
netCDF::NcVar dataVar
is a single variable, dataFile.getVars()
returns multiple variables in a map. The simplest fix is to use: netCDF::NcVar dataVar
是单个变量, dataFile.getVars()
在 map 中返回多个变量。最简单的解决方法是使用:
auto dataVar = dataFile.getVars();
Or:要么:
std::multimap< std::string, NcVar > dataVar = dataFile.getVars();
If you actually wanted to get a single variable you need to provide a name:如果你真的想得到一个单一的变量,你需要提供一个名字:
netCDF::NcVar dataVar = dataFile.getVar("myvar");
Seehttp://unidata.github.io.netcdf-cxx4/clas.netCDF_1_1NcFile.html参见http://unidata.github.io.netcdf-cxx4/clas.netCDF_1_1NcFile.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.