I created this fake loading function just so my program looks more cool to the examiner but the thing is i want the previous loading to disappear.
for example i want the loading 10% to appear then loading 20% comes in place of loading 10% and loading 10% disappears and then loading 30% comes and so on.
Also please suggest an efficient method such that i dont have to write std::this_thread thing again and again after each line.
Unless you clear the screen before each print, I do not believe there is a way to achieve what you are looking for with command line c++. With a gui, you could simply update the label or string that shows the loading message.
Anytime you ask, is there any way to avoid writing xxx again and again, you should start thinking function. In your case, a very simple function like the following
1 2 3 4 5 6
void sleep(int sec)
{
std::this_thread::sleep_for(std::chrono::seconds(sec));
}
//now you can use sleep(2);
Try using \r to return the carriage position to the start of the line.
This implies that each line must be the same length or longer than the previous line.
This also assumes the OS supports \r.