You can use conio.h
under windows. You would simply read and process any keyboard input in a while
loop. Here is a simple example:
#include <conio.h>
#include <iostream>
#include <list>
int main()
{
std::list<char> myChars; // to store what your chars
std::cout << "START WRITING: ";
while(true)
{
// read the character and perform some logic
char val = _getch();
if (static_cast<int>(val) == 8) // backspace: pop_back
{
myChars.pop_back();
std::cout << "\b" << " " << "\b";
/* no idea how to go up to the previous line in a console :( */
}
else if (static_cast<int>(val) == 13) // enter/return: new line
{
myChars.push_back('\n');
std::cout << "\n";
}
else if (static_cast<int>(val) == 27) // escape: exit
{
break;
}
else // push_back
{
myChars.push_back(val);
std::cout << val;
}
}