//keep_it_open.h
#ifndef KEEP_IT_OPEN_H
#define KEEP_IT_OPEN_H
class keep_open{
public:
~keep_open();
};
extern keep_open KeepOpen; //I'm not sure if this is the correct way for creating the object
#endif
1 2 3 4 5 6 7 8 9 10 11
//keep_it_open.cpp
#include "keep_it_open.h"
#include <iostream>
#include <limits>
keep_open::~keep_open(){
std::cout << "Press Enter to end ";
std::cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n');
}
keep_open KeepOpen;
This way if I want the "release" version I just compile main.cpp
But g++ *.cpp will keep the console open. (it works with exit, but fail with exceptions)
If no matching handler is found in a program, the function terminate() (_except.terminate_) is called. Whether or not the stack is unwound before calling terminate() is implementation-defined.
Yes, but the code will be dirtied.
main.cpp will need to #include "keep_it_open.h" , and the object must be created inside the try block, (and you need the try/catch)
That's what I'm trying to do. But the idea was that the program to be tested will be as clean as possible, so I could pass from the test to the release with minimal change.
In this case