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日

悬赏问题

  • ¥30 酬劳2w元求合作写文章
  • ¥15 在现有系统基础上增加功能
  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图