samedi 25 septembre 2021

Safely shutting down program from c++ function

I want to make a program that will perform some math after reading from user input files.

During the reading process (a function) I want to check if the user syntax in the file is correct, otherwise I would like to shutdown the program so that the user can modify the file(s= accordingly and run it again.

The structure will be something like this:

int main(int argCount, char *args[])
{
   std::string fileName = "PathOfFile";
   int a = GetUserInput(fileName, variableName);
   int b = GetUserInput(fileName, variableName);

   // Other functions will be placed here
   return 0;
}

int GetUserInput(std::string filename, std::string variableName)
{
 // Some routine to read the file and find the variableName 
 // Some routine to check the syntax of the user input. 
    // Let us assume that the integers are to be fined as: variableName 1;
    // and I want to check that the ; is there. Otherwise, shutdown the program.     
}

How can I shutdown the program safely from the function GetUserInput? Is there any C++ to signal that the program must wrap up and exit?

Aucun commentaire:

Enregistrer un commentaire