diff --git a/main.cpp b/main.cpp index 7e83ef8..33a48c8 100644 --- a/main.cpp +++ b/main.cpp @@ -1,11 +1,33 @@ #include -std::string* test() { - static std::string tr {"test"}; - return &tr; -} +using string = std::string; +void ignoreTillLineEnd(); +string promptfs(string); int main() { - std::cout << *test(); + string name {promptfs("Enter your name:")}; + std::cout << "Hello " << name << "\n"; + return 0; +} + +void ignoreTillLineEnd() { + std::cin.ignore(std::numeric_limits::max(), '\n'); +} + +string promptfs(string msg) { + bool once {false}; + string toret {}; + do { + if (once) { + std::cin.clear(); + std::cout << "Input Failure!\n"; + } + std::cout << msg << "\n"; + std::cin >> toret; + ignoreTillLineEnd(); + once = true; + } + while (std::cin.fail()); + return toret; }