전현진

add exit function

1 #include "EchoString.h" 1 #include "EchoString.h"
2 2
3 +const std::string EchoString::mExitMessage = "exit";
4 +
3 void EchoString::PrintScreen() 5 void EchoString::PrintScreen()
4 { 6 {
5 std::cout << "Echo Program : "; 7 std::cout << "Echo Program : ";
...@@ -8,9 +10,9 @@ void EchoString::PrintScreen() ...@@ -8,9 +10,9 @@ void EchoString::PrintScreen()
8 10
9 void EchoString::InputString() 11 void EchoString::InputString()
10 { 12 {
11 - while (getEcho().empty()) 13 + while (true)
12 { 14 {
13 - std::cout << "Input your string : "; 15 + std::cout << "Input your string(EXIT : \"exit\") : ";
14 std::getline(std::cin, mEcho); 16 std::getline(std::cin, mEcho);
15 17
16 if (std::cin.fail()) 18 if (std::cin.fail())
...@@ -20,6 +22,8 @@ void EchoString::InputString() ...@@ -20,6 +22,8 @@ void EchoString::InputString()
20 system("cls"); 22 system("cls");
21 continue; 23 continue;
22 } 24 }
25 +
26 + break;
23 } 27 }
24 } 28 }
25 29
......
...@@ -7,6 +7,7 @@ class EchoString ...@@ -7,6 +7,7 @@ class EchoString
7 { 7 {
8 private: 8 private:
9 std::string mEcho; 9 std::string mEcho;
10 + static const std::string mExitMessage;
10 11
11 public: 12 public:
12 void PrintScreen(); 13 void PrintScreen();
...@@ -19,6 +20,7 @@ public: ...@@ -19,6 +20,7 @@ public:
19 void setEcho(const std::string& echo) { mEcho = echo; } 20 void setEcho(const std::string& echo) { mEcho = echo; }
20 std::string getEcho() const { return mEcho; } 21 std::string getEcho() const { return mEcho; }
21 std::string getEcho() { return mEcho; } 22 std::string getEcho() { return mEcho; }
23 + std::string getExitMessage() { return mExitMessage; }
22 24
23 }; 25 };
24 26
......
...@@ -7,8 +7,14 @@ int main() ...@@ -7,8 +7,14 @@ int main()
7 { 7 {
8 EchoString echo; 8 EchoString echo;
9 9
10 + while (true)
11 + {
10 echo.InputString(); 12 echo.InputString();
13 + if (echo.getEcho() == echo.getExitMessage())
14 + break;
15 +
11 echo.PrintScreen(); 16 echo.PrintScreen();
17 + }
12 18
13 return 0; 19 return 0;
14 } 20 }
...\ No newline at end of file ...\ No newline at end of file
......