Created
June 26, 2018 00:02
-
-
Save junzengx14/04f9d93643cc9b33a6e7a886046c684f to your computer and use it in GitHub Desktop.
To print in a fixed line in cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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