Home > database >  What type should I make a function that returns an exit state in C
What type should I make a function that returns an exit state in C

Time:10-23

I am writing a function that checks whether a file can be opened or not. However, I don't know if bool is the correct type.

Any help would be appreciated.

Thanks!

bool checkFileOpen (ifstream fin)
{
  if (!fin)
  {
    cout << "Unable to open file";
    return EXIT_FAILURE;
  }
}

CodePudding user response:

They are intended to be returned from main or passed to exit, so the proper type is int.

CodePudding user response:

According to https://en.cppreference.com/w/c/program/EXIT_status, those macros are /*implementation defined*/

You can either look it up for your platform, or translate to the type of your chooosing.

  • Related