Skip to content

Instantly share code, notes, and snippets.

@junzengx14
Created June 26, 2018 00:02
Show Gist options
  • Save junzengx14/04f9d93643cc9b33a6e7a886046c684f to your computer and use it in GitHub Desktop.
Save junzengx14/04f9d93643cc9b33a6e7a886046c684f to your computer and use it in GitHub Desktop.
To print in a fixed line in cpp
#include <iostream>
#include <string>
#include <sstream>
#include <stdlib.h>
#include <unistd.h>
int main()
{
std::string s = "Acceleration X Acceleration Y Acceleration Z";
std::cout << s << std::endl;
for (int i = 0; i < 1000; ++i)
{
// use \r before the desired string
std::cout << "\r" << std::to_string(i) << std::flush;
sleep(1);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment