Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - Daaa22

Pages: [1]
1
General / String erase problem while using Event::TextEntered
« on: March 20, 2022, 06:00:23 pm »
#include <SFML/Graphics.hpp>
#include <iostream>

using namespace std;
using namespace sf;

int main()
{
    Keyboard keyboard;

    RenderWindow window( VideoMode( 800, 600 ), "..." );

    string help;

    while( window.isOpen() )
    {
        Event event;

        while( window.pollEvent( event ) )
        {
            if( event.type == Event::Closed )
                window.close();

            if( event.type == Event::KeyPressed && keyboard.isKeyPressed( Keyboard::Backspace ) )
            {
                help.erase( help.end() - 1 );
                cout << help << endl;
            }
            else if ( event.type == Event::TextEntered && event.text.unicode < 128 )
            {
                help += static_cast<char>(event.text.unicode);
                cout << help << endl;
            }
        }

        window.display();
    }

    return 0;
}
 

Try running it, type anything you would like and try to use backspace. Used once works good, but if i try to delete second character then nothing changes in my string. How to solve this?

Pages: [1]
anything