I try to open a file in a function in a class:

void openFile(){

    inputFile.open(inputFilename.c_str());

    if (inputFile.is_open()){
      inputFile.read(buffer, skipAtBegin);
    } else {
      cerr << "Cannot open file: " << inputFilename << endl;
      exitNow();
    }
}

In main() i would just return 1, but how can i do this in a sub-sub-function-class the best/simplest way??

Return 1 all steps up to main?

Use ecxeptions?

Any exit() commands?

有帮助吗?

解决方案

Usually there are three Options:

  1. Use exit. Quit the program.
  2. Use exception. Throw exceptions, handles elsewhere.
  3. Set global status variable. Set global status, and let other functions checkt the status and handle it.

Hope someone would come up with other options.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top