<分区>
我正在尝试在这里完成二进制 i/o,但我一直收到这个错误,这是...
no matching function for call to 'std::basic_ofstream<char>::write(int*,unsigned int)'
和
no matching function for call to 'std::basic_ofstream<char>::write(double*,unsigned int)'
这是我的代码...
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
int x = 123;
double fx = 12.34;
ofstream myfile("filename.dat", ios::out | ios::binary);
myfile.write(&x, sizeof(x));
myfile.write(&fx, sizeof(fx));
myfile.close();
return 0;
}
我发现其他多个帖子也有同样的情况,但他们的解决方法通常是输入...
ofstream myfile(filename.c_str(), ios::out | ios::binary);
当我尝试多次时,编译器仍然对我尖叫。我正在使用 QT Creator 作为我的 IDE,我已经验证它使用的是 C++11。并且还在 Code::Blocks 中运行相同的代码并得到相同的错误。它不喜欢我传递给它的文件名参数。我认为这与第一个参数是 ofstream open() 的成员函数的 const char 有关吗?!
void open(const char *filename, [int mode], [int prot]);
我在这里不理解/遗漏了什么?