C++ 将uchar*数据写入文件
我正在使用OpenCV库,它有一个名为C++ 将uchar*数据写入文件,c++,C++,我正在使用OpenCV库,它有一个名为Mat的类,表示一个矩阵,数据存储在uchar*Mat::data的数组中。我想用C++将这些数据写入一个二进制文件 这是我的密码: cv::Mat m(3, 3, CV_8UC1); // This basically creates a 3-by-3 matrix std::fstream fileOut("file.bin", std::ios::out | std::ios::binary); fileOut.write((char*)m.data,
Mat
的类,表示一个矩阵,数据存储在uchar*Mat::data
的数组中。我想用C++将这些数据写入一个二进制文件
这是我的密码:
cv::Mat m(3, 3, CV_8UC1); // This basically creates a 3-by-3 matrix
std::fstream fileOut("file.bin", std::ios::out | std::ios::binary);
fileOut.write((char*)m.data, 9); // This should write 9 bytes of data
我收到了错误信息:
invalid conversion from ‘uchar* {aka unsigned char*}’ to ‘std::basic_istream<char>::char_type* {aka char*}’
从'uchar*{aka unsigned char*}'到'std::basic\u istream::char\u type*{aka char*}的转换无效
我该怎么做呢?在C语言中这是非法的转换++
使用
reinterpret\u cast(m.data)
为什么不使用-OpenCV提供的FileStorage
类进行持久化-?哪个编译器?对我来说,VS2010上的代码很好。