The following C++ code works fine when compiling with g++ on Ubuntu 18.04:
#include <iostream>
using namespace std;
void wait(){
int t0 = time(0);
while(true){
if(time(0) >= t0 + 1){
return;
}
}
}
int main(){
while(true){
cout << "tick\n"; //Line 15
wait();
}
}
This is the output where one tick
appears every second:
tick
tick
tick
tick
tick
However when removing the \n
in line 15 it seems to just be stuck somewhere and nothing happens.
What exactly is \n
doing to the code? What do I do if I don't want to print in a new line after every cycle? (I assume that calling this a bug in C++ would be a bit arrogant and wrong)
Also, I know that this is probably a very bad way of building a delay function, I'm just messing around a bit.