Heh, I'm having too much fun with this :)
It's been WAAAY overdone, but I've improved the code significantly:
Code:
std::string GetInputDefault(const std::string &defaultin, std::ostream &out = std::cout)
{
std::vector<char> inputvec(defaultin.begin(), defaultin.end());
out << defaultin;
while (true)
{
int in = getch(); // Get keycode
switch (in)
{
case 13: // Enter
return std::string(inputvec.begin(), inputvec.end());
case 8: // Backspace
if (inputvec.size() != 0)
{
inputvec.pop_back(); // Remove last character entered
out << "\b \b" << std::flush; // Remove from screen
}
break;
default:
inputvec.push_back(in); // Insert character
out << static_cast<char>(in) << std::flush; // Print
}
}
}
edit: Thanks Sang-Drax