我正在尝试将一个 int 数组写入 fstream,但是当我调用fstream.write
.
我可以使用fstream
将 int 数组写入文件吗?
int main(int argc, char * argv[])
{
fstream amostra("D:\\Amostra.txt", ios::out | ios::binary);
const int total_elements_block = 1024;
const int buffer_size = total_elements_block;
const int total_buffer = 10;
int * buffer = new int [buffer_size];
//for (int j=0; j<total_buffer; j++){
for (int i =0; i<total_elements_block; i++){
buffer[i] = i;
}
amostra.write((char *)(&buffer), total_elements_block*4);
//}
amostra.close();
delete []buffer;
return 0;
}