1
0
LearningCPP/main.cpp

34 lines
711 B
C++

#include <iostream>
using string = std::string;
void ignoreTillLineEnd();
string promptfs(string);
int main()
{
string name {promptfs("Enter your name:")};
std::cout << "Hello " << name << "\n";
return 0;
}
void ignoreTillLineEnd() {
std::cin.ignore(std::numeric_limits<std::streamsize>::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;
}