首页 > 解决方案 > 我应该如何处理:错误 C2039 'assign': is not a member of 'cl::string' in Visual Studio 2017?

问题描述

我想在 Visual Studio C++ 中构建一个简单的 OpenCL 代码,但在构建过程中出现错误。错误是

Error C2039 'assign': is not a member of 'cl::string'

问题是关于cl::stringstd::string但是,当我使用而不是构建代码时cl::string,它工作得很好。我应该如何处理?

这是代码:

#define __CL_ENABLE_EXCEPTIONS
#define __NO_STD_STRING
#include <iostream>


#ifdef MAC
#include<OpenCL.hpp>
#else
#include<CL/cl.hpp>
#endif // MAC



int main() {

    std::vector < cl::Platform > platforms;
    cl::string platformVendorName;

        cl::Platform::get(&platforms);
        std::cout << "There are " << platforms.size() << " platforms." << 
        std::endl << std::endl;
        for (size_t j = 0; j < platforms.size(); j++)
        {   
            platformVendorName = platforms[j].getInfo<CL_PLATFORM_VENDOR>();

            std::cout << "CL_PLATFORM_VENDOR: " << 
            platformVendorName.c_str() << std::endl;

        }

    system("pause");
    return 0;
}

标签: c++stringopencl

解决方案


为什么不使用 std::string?

至少从 OpenCL 1.2 起,命名空间中string定义的类已被弃用,不推荐使用它。cl取自cl.hpp

/*! \class string
 * \brief Simple string class, that provides a limited subset of std::string
 * functionality but avoids many of the issues that come with that class.

 *  \note Deprecated. Please use std::string as default or
 *  re-define the string class to match the std::string
 *  interface by defining STRING_CLASS
 */
class CL_EXT_PREFIX__VERSION_1_1_DEPRECATED string CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED

推荐阅读