backspacing over a string doesn't delete it

This is a discussion on backspacing over a string doesn't delete it within the C++ Programming forums, part of the General Programming Boards category; I noticed, while working on a program, that when i backspace in the input line, it does not delete the ...

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    69

    backspacing over a string doesn't delete it

    I noticed, while working on a program, that when i backspace in the input line, it does not delete the characters on the line. It merely moves the cursor back a space and allows me to type over the characters.

    When i enter that string, it leaves all the characters that should have been removed by backspace in the string:

    Code:
    stupid account die@jeff ~/sample
    $ ./input
    Input a line, and try backspacing over it and correcting it.
    why won't it delete these from the string?f;lskf;sdj
    Here is the string as detected by the system:
    why won't it delete these from the string?f;lskf;sdj
    stupid account die@jeff ~/sample
    $
    here is the simple code that i'm running, which doesn't have any room for errors:

    Code:
    #include <iostream>
    #include <string>
    using namespace std;
    
    int main()
    {
    	string input;
    
    	cout<<"Input a line, and try backspacing over it and correcting it." <<endl;
    	getline(cin,input);
    	cout<<"Here is the string as detected by the system:" <<endl;
    	cout<<input;
    
    	return EXIT_SUCCESS;
    }
    anybody know why this is happening? i don't recall this happening when running programs in windows (this is under bash on linux)

  2. #2
    Registered User
    Join Date
    Mar 2004
    Posts
    494
    not sure if i understand it but when i type in something, then backspace and correct it, then hitting enter it gives me the string after the backspacing(the correct string), im on windows btw

  3. #3
    Registered User
    Join Date
    Oct 2002
    Posts
    69
    i suppose this is a linux/unix specific question then, as i don't recall having that happen when i use that in windows.

    i just created another version of the program, but replaced the getline(cin, input) with cin>>input; and it still does the same thing.




    if it wasn't clear, in the first post i typed in a bunch of random characters, backspaced to the beginning of the line, and typed "why won't it delete these from the string?". the characters after that remained from before i backspaced.

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    This isn't a C++ issue, it's a Linux shell issue.
    My best code is written with the delete key.

  5. #5
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Try using ctrl-h and see if that works.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  6. #6
    Registered User
    Join Date
    Oct 2002
    Posts
    69
    nope, ctrl+h had the same effect as backspace.

    this is kind of like the issue of typing in an assembly program, it just takes the input without letting you completely modify it (in assembly it would just take each character as it was entered, this one just takes the final string without allowing deletion)

    strange!

  7. #7
    wierd guy bart's Avatar
    Join Date
    Aug 2001
    Posts
    87
    Code:
    user1@bart:~/temp$ ./a.out
    Input a line, and try backspacing over it and correcting it.
    hello
    Here is the string as detected by the system:
    hello
    user1@bart:~/temp$ ./a.out
    Input a line, and try backspacing over it and correcting it.
    jacl^Hob
    Here is the string as detected by the system:
    jacob
    user1@bart:~/temp$
    Works for me (g++ 3.2.2 under bash in slackware linux).

    I did add a "<<endl" after "cout<<input". But i doubt that makes a difference.

  8. #8
    Registered User
    Join Date
    Oct 2002
    Posts
    69
    well, i guess it's just a problem with console bash in cygwin, i just tried it from konsole in KDE under cygwin, and it worked fine

  9. #9
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Just a quickie suggestion to verify that the backspace is doing what you think it is, try:
    Code:
    $ stty erase ^H
    And see if the problem persists.
    My best code is written with the delete key.

  10. #10
    Registered User
    Join Date
    Oct 2002
    Posts
    69
    wow, when i typed that, it deleted the word erase from the string. but when i type two or more words, it deletes the rest except for the first contiguous string of characters.

    at least that makes some stuff go away

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. char Handling, probably typical newbie stuff
    By Neolyth in forum C Programming
    Replies: 16
    Last Post: 06-21-2009, 05:05 AM
  2. Replies: 8
    Last Post: 04-25-2008, 03:45 PM
  3. Inheritance Hierarchy for a Package class
    By twickre in forum C++ Programming
    Replies: 7
    Last Post: 12-08-2007, 04:13 PM
  4. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  5. problems with overloaded '+' again
    By Brain Cell in forum C++ Programming
    Replies: 9
    Last Post: 04-14-2005, 06:13 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21