How can I control the command prompt with c++ in linux? I am using bash.

For learning, I am trying to make a rotating bar using | \ - / characters

print |
erase
print \
erase
print -
erase
print /

...and this would be looped

I just need to know how to stream to the command prompt and how to erase characters