w2397951871 2022-03-22 21:17 采纳率: 100%
浏览 227
已结题

C++问题error C2039: 'perror' : is not a member of 'std'

#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'

  • 写回答

1条回答 默认 最新

  • 春休夏末 2022-03-22 21:23
    关注

    14行 21行 perror函数前面的std::删一下 15行 22行 exit函数前面的std::删一下

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 3月30日
  • 已采纳回答 3月22日
  • 修改了问题 3月22日
  • 创建了问题 3月22日

悬赏问题

  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来