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

后端 未结 4 1315
情书的邮戳
情书的邮戳 2020-12-24 01:22

Is it possible on Windows without using WinAPI?

相关标签:
4条回答
  • 2020-12-24 02:02

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

    0 讨论(0)
  • 2020-12-24 02:04

    This code does exactly that:

    std::cout<<"\b \b";
    
    0 讨论(0)
  • 2020-12-24 02:18

    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

    0 讨论(0)
  • 2020-12-24 02:27

    No.

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

    0 讨论(0)
提交回复
热议问题