전현진

add exit function

#include "EchoString.h"
const std::string EchoString::mExitMessage = "exit";
void EchoString::PrintScreen()
{
std::cout << "Echo Program : ";
......@@ -8,9 +10,9 @@ void EchoString::PrintScreen()
void EchoString::InputString()
{
while (getEcho().empty())
while (true)
{
std::cout << "Input your string : ";
std::cout << "Input your string(EXIT : \"exit\") : ";
std::getline(std::cin, mEcho);
if (std::cin.fail())
......@@ -20,6 +22,8 @@ void EchoString::InputString()
system("cls");
continue;
}
break;
}
}
......
......@@ -7,6 +7,7 @@ class EchoString
{
private:
std::string mEcho;
static const std::string mExitMessage;
public:
void PrintScreen();
......@@ -19,6 +20,7 @@ public:
void setEcho(const std::string& echo) { mEcho = echo; }
std::string getEcho() const { return mEcho; }
std::string getEcho() { return mEcho; }
std::string getExitMessage() { return mExitMessage; }
};
......
......@@ -7,8 +7,14 @@ int main()
{
EchoString echo;
while (true)
{
echo.InputString();
if (echo.getEcho() == echo.getExitMessage())
break;
echo.PrintScreen();
}
return 0;
}
\ No newline at end of file
......