std:: cout para imprimir caracteres N veces
¿Cómo puedo imprimir un carácter N número de veces usando std::cout
sin bucle?
¿Hay alguna manera de mover el cursor de texto hacia atrás para anular el efecto de std::cout << std::endl;
? es decir, para subir una línea (digamos que nunca imprimimos nada después de hacer la operación std::cout << std::endl;
).
31
3 answers
std::cout << std::string(100, '*') << std::endl;
Para mover una línea, debe recurrir a escapes de terminal (suponiendo que isatty()
indica que se está ejecutando en uno).
57
Author: sehe,
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
2011-10-25 23:48:28
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
2011-10-25 23:48:28
std::cout << std::setfill(the_char) << std::setw(100) << "";
14
Author: Benjamin Lindley,
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
2011-10-25 23:58:18
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
2011-10-25 23:58:18
¿Hay una manera de respaldar nuestro camino para anular el efecto de cout
Use el operador ternario (o una sentencia if si se refiere) ... algo así ...
void PrintCharNtimes(char chatToPrint; int numTimes)
{
std::cout << std::string(numTimes, chatToPrint) << (numTimes > 0) ? std::endl : ;
}
0
Author: Mawg,
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
2011-10-25 23:56:03
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
2011-10-25 23:56:03