How to remove last character put to std::cout?

▼魔方 西西 提交于 2019-12-03 18:40:22

问题


Is it possible on Windows without using WinAPI?


回答1:


You may not remove last character.

But you can get the similar effect by overwriting the last character. For that, you need to move the console cursor backwards by outputting a '\b' (backspace) character like shown below.

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

So the output would be

H




回答2:


No.

You can't without accessing the console's api that is never standard.




回答3:


This code does exactely that std::cout<<"\b \b";




回答4:


You can also use cin.get() to delete last char



来源:https://stackoverflow.com/questions/3745861/how-to-remove-last-character-put-to-stdcout

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!