添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Greetings all !
I have a piece of sample code from an open library. It was supposedly written for msvs, but I am using codeblocks with mingw compiler on a windows 7 machine.
The (so I think) relevant piece of code is:
1
2
3
4
5
#include <iostream>
#include <errno.h>
#include <stdio.h>
errno_t err;
The error I get is :
error: 'errno_t' was not declared in this scope|
I searched online for what to do with errno_t, but all I figured out is about its purpose. What can I do to fix this and make the program work ? Thank you.
Kind regards, T http://www.cplusplus.com/reference/cerrno/errno/
http://en.cppreference.com/w/cpp/header/cerrno
I don't think errno_t exists. Instead, you should try decltype (errno) By using the typedef keyword, you make err a type instead of a variable.
However, in this case since you immediately assign to the variable, you can forget about the data type and let the compiler figure it out for you: auto err = fopen(&infile, infilename, "r" );
Though, really, if you are going to use C++ at all, you should use it completely and ignore C:
1
2
3
4
5
6
7
8
if(std::ifstream infile {infilename})
    //success
    //error
There's generally no use for detailed error information except in specialized cases. For the most part, your only concern is whether you could open the file or not.
Last edited on