diff --git a/Stopwatch.hpp b/Stopwatch.hpp index a8c723d..df835a8 100644 --- a/Stopwatch.hpp +++ b/Stopwatch.hpp @@ -191,7 +191,13 @@ public: hasStarted = hasStopped = false; //Set the flags as though nothing has happened endTime = startTime = std::chrono::high_resolution_clock::time_point(); //Set the times with a blank time } + friend std::ostream& operator<<(std::ostream& out, Stopwatch& timer); }; //end class Stopwatch +std::ostream& operator<<(std::ostream& out, Stopwatch& timer){ + out << timer.getStr(); + bool num = timer.hasStopped; + return out; +} } //end namespace mee #endif //end STOPWATCH_HPP diff --git a/testStopwatch.cpp b/testStopwatch.cpp index 20f2e25..b765c29 100644 --- a/testStopwatch.cpp +++ b/testStopwatch.cpp @@ -17,34 +17,34 @@ int main(){ std::cout << "Test failed" << std::endl; } catch(mee::Stopwatch::invalidTimeResolution){ - std::cout << "There was an invalid time resolution" << std::endl; + std::cout << "There was an invalid time resolution\n"; std::cout << "Test failed" << std::endl; } catch(mee::Stopwatch::timeBeforeStart){ - std::cout << "Tried to get time before the stopwatch was started" << std::endl; + std::cout << "Tried to get time before the stopwatch was started\n"; std::cout << "Test failed" << std::endl; } catch(mee::Stopwatch::stopBeforeStart){ - std::cout << "Tried to stop the stopwatch before it was started" << std::endl; + std::cout << "Tried to stop the stopwatch before it was started\n"; std::cout << "Test successful" << std::endl; } //Try to get the time on it without starting it std::cout << "Testing the timeBeforeStart error" << std::endl; try{ - std::cout << timer.getStr() << std::endl; + std::cout << timer.getStr() << '\n'; std::cout << "Test failed" << std::endl; } catch(mee::Stopwatch::invalidTimeResolution){ - std::cout << "There was an invalid time resolution" << std::endl; + std::cout << "There was an invalid time resolution\n"; std::cout << "Test failed" << std::endl; } catch(mee::Stopwatch::timeBeforeStart){ - std::cout << "Tried to get time before the stopwatch was started" << std::endl; + std::cout << "Tried to get time before the stopwatch was started\n"; std::cout << "Test successful" << std::endl; } catch(mee::Stopwatch::stopBeforeStart){ - std::cout << "Tried to stop the stopwatch before it was started" << std::endl; + std::cout << "Tried to stop the stopwatch before it was started\n"; std::cout << "Test failed" << std::endl; } @@ -56,19 +56,20 @@ int main(){ int num = cnt; } timer.stop(); - std::cout << "It took " << timer.getStr() << " to complete this loop" << std::endl; + std::cout << "It took " << timer.getStr() << " to complete this loop\n"; + std::cout << "It took " << timer << " to complete this loop\n"; std::cout << "Test successful" << std::endl; } catch(mee::Stopwatch::invalidTimeResolution){ - std::cout << "There was an invalid time resolution" << std::endl; + std::cout << "There was an invalid time resolution\n"; std::cout << "Test failed" << std::endl; } catch(mee::Stopwatch::timeBeforeStart){ - std::cout << "Tried to get time before the stopwatch was started" << std::endl; + std::cout << "Tried to get time before the stopwatch was started\n"; std::cout << "Test failed" << std::endl; } catch(mee::Stopwatch::stopBeforeStart){ - std::cout << "Tried to stop the stopwatch before it was started" << std::endl; + std::cout << "Tried to stop the stopwatch before it was started\n"; std::cout << "Test failed" << std::endl; }