deleting a character that was written at the command promt

if I cout<<" bla bla bla "; i get bla bla bla

how can i delete the last "bla " so it apears like bla bla



Answer this question

deleting a character that was written at the command promt

  • Michael G

    Strange question. How about cout << "bla bla" Or cout << "bla bla bla\b\b\b \b\b\b".



  • abehead12310

    I know the question sounds strange but I tried to make it mor simpler . here's the real problem : I want to cout a messege and after the user has pressed a key, a part of the messege should disapear .

    I tried this cout<<" wdjfnkjvnfkjvnkvdklvnfjkvfv";

    if(_gettch()) cout<<(char)8;

    it didn't delete anything

    backspace=8;

    sorry if my English is funy ( is't not my native language)


  • Frank Showalter

    You're close with cout << char(8) which is the same as cout << "\b". It puts the cursor back by one position. Now you need to output a space to overwrite the last character. And another "\b" to put the cursor back again. So every cout << "\b \b" erases one character at a time.



  • Aaron Mathison

    You can't fix that problem with a simple "\b" trick. Start reading here for Windows API functions that work with the console.




  • TrulsTveoy

    this should be sipmle string manipulation.
    look for the space and then do what u want to do

    cheers

  • moto822

    thanks!

    it works .

    there stil is a probleme: if the messege is to long and it has to be written on 2

    or more lines , cout<<(char)8; and cout<<"\b"; won't work!!!!!!!!!!!

    ex : cout<<"fgfdjikgnfgkjnfskgsdfjhabfvhafbvfhvbfvjadbfjvhbfdvahdbfvhfadbvfdvfdv";

    cout<<"dfdsfhgbjfdfNVVOBMNIBOBIBFJVVHBFHBhjbdfvafignbmifsoivjbnb";

    cout<<"fbnkvjnkjnvkfjvnfkvjnjvfjvkvjkvvdfdfvfdkvfdlvjfdkvjfvkjfdvfvjkafjvvjfvnfjvnfv";

    // x=lenght_of_messege;

    for(int z=x ; z>0; z-- ) cout<<"\b";

    only deletes the last line

    how can I delete all lines


  • deleting a character that was written at the command promt