#include <iostream>
#include <fstream> //文件输入输出流
#include <time.h>
using namespace std;
int main()
{
std::ifstream fileIn; //输入流(读取文件数据)
std::ofstream fileOut; //输出流(写入文件数据)
//打开文件
fileIn.open("ZFS_Head_Hair_Binary.STL",std::ios::binary);
if (!fileIn.is_open())
{
std::perror("fileIn.open");
std::exit(0);
}
fileOut.open("final_binary_c++.stl", std::ios::binary);
if (!fileOut.is_open())
{
fileIn.close();
std::perror("fileOut.open");
std::exit(0);
}
fileIn.seekg(0, std::ios::end); //设置文件末尾位置
unsigned _int64 ullLength = fileIn.tellg(); //得到文件长度
fileIn.seekg(0, std::ios::beg); //设置文件起始位置
//一次全部读取文件(已测试成功)
char* buffer = new char[ullLength];
fileIn.read(buffer, 80); //读文件,此处包含文件名80个字节和三角形个数4个字节,共计84字节
//一次全部写入文件(已测试成功)
fileOut.write(buffer, 80); //写文件
int num[1] ;
fileIn.read((char*)num,4);
fileOut.write((char*)num,4);
//cout<<num[0]<<endl; //num[0]为三角形个数
for(int n=0;n<num[0];n++){
float xyz[4][3];
for(int i=0;i<4;i++){
for(int j=0;j<3;j++){
fileIn.read((char*)xyz,4);
xyz[0][0]=xyz[0][0]*2;
fileOut.write((char*)(xyz),4);
}
}
char* buff = new char[2];
fileIn.read(buff,2);
fileOut.write(buff,2);
}
//循环读取文件,循环写入文件
// int nSize = 1024; //每次读写文件元素的大小
// char* buffer = new char[nSize];
// while (!fileIn.eof())
// {
// std::memset(buffer, 0, nSize);
// fileIn.read(buffer, nSize); //读取文件数据
// ullLength -= nSize;
// if (ullLength <= nSize)
// fileOut.write(buffer, ullLength); //写入文件数据
// else
// fileOut.write(buffer, nSize); //写入文件数据
// }
//释放内存
delete[]buffer;
//关闭文件
fileIn.clear();
fileIn.close();
fileOut.clear();
fileOut.close();
std::cout << "Finished" << std::endl;
std::cout << "The run time is: " <<(double)clock() / CLOCKS_PER_SEC << "s" << std::endl;
return 0;
}
出现了以下错误
error C2039: 'perror' : is not a member of 'std'
error C2039: 'exit' : is not a member of 'std'