这里是代码问题提交
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
int main()
{
ofstream out("test", ios::out | ios::binary);
if(!out) {
cout << "Cannot open output file.\n";
return 1;
}
double num = 100.45;
char str[] = "www.java2s.com";
out.write((char *) &num, sizeof(double));
out.write(str, strlen(str));
out.close();
return 0;
}
我不明白只有这
out.write((char *) &num, sizeof(double));
为什么我们需要(char *)&num?
或sizeof(double)?
出于好奇,是否有什么理由可以在这种情况下使用流插入操作符('operator <<()')?您不必担心使用此类转换。 – Void 2010-07-28 20:53:00
与许多其他问题不同,这是我们可以回答的那种问题 - 相当清晰,真实的代码 - 我是否检测到有多人使用您的帐户? “ – 2010-07-28 20:55:01