std::cout is slow ( mainly with Windows ) so your FPS reduce and your attack function is called less often.
How do you call it ? I mean, do you test with sf::Input if the key is down ? Or do you use sf::Event ?
If you're using sf::Input you need a clock to turn off temporarily the call of the function.
If you're using sf::Event, disabling key repeat should be enough.