You can do something like this to get you started.
But I recommend maybe you look into state machines if your game is going to get complex.
// Couple of ways to do it.
// #1 Player position is the same as his previous position
if(playerPos == prevPlayerPos){
// change animation to idle
}
// #2 Player velocity = 0, player is not moving
if(playerVel.x == 0 && playerVel.y == 0){
// change animation to idle
}
#3
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) {
// change animation to left
}
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) {
// change animation to right
}
else{
// change animation to idle
}
}
Hope this helps you get started.