¿Cómo eliminar el último carácter puesto a std:: cout?


¿Es posible en Windows sin usar WinAPI?

Author: Xirdus, 2010-09-19

3 answers

No puede eliminar el último carácter.

Pero puede obtener el efecto similar sobrescribiendo el último carácter. Para ello, es necesario mover el cursor de la consola hacia atrás mediante la salida de un carácter '\b' (retroceso) como se muestra a continuación.

#include<iostream>
using namespace std;
int main()
{
    cout<<"Hi";
    cout<<'\b';  //Cursor moves 1 position backwards
    cout<<" ";   //Overwrites letter 'i' with space
}

Así que la salida sería

H

 67
Author: bjskishore123,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-09-19 13:47:59

No.

No se puede sin acceder a la api de la consola que nunca es estándar.

 5
Author: Klaim,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-09-19 13:34:39

Este código hace exactamente que std::cout<<"\b \b";

 -1
Author: Hassen Dhia,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-04-12 19:23:25