Hello guys, i just wanna ask how to control couts. for example:
cout<<"Hello"<<endl;
cout<<"end"<<endl;
how to control it so it will display:
Hello
//after few seconds for example 2 seconds
end
please reply if you don't understand my question. Thanks :D
anyway, (2000-clock()>0) would show end 2s after hello ?
It might. It might not. The granularity of clock is implementation defined as is the initial value returned from clock at the beginning of a program (it is not required to be 0.) Spinning in a loop doing nothing is not a great recommendation unless you like 100% utilization of your cpu checking to see if it's done waiting. Use an operating specific function (such as Sleep on Windows) or if you have C++11 support:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include <iostream>
#include <thread>
#include <chrono>
int main()
{
constchar* helloWorld = "Hello world!";
auto delay = std::chrono::milliseconds(500);
for (constchar* p = helloWorld; *p; ++p)
{
std::cout << *p;
std::this_thread::sleep_for(delay);
}
}
Your compiler version would be more relevant than that of your IDE, although you're two major versions behind on Code::Blocks (which may mean you would need to specify the option for C++11 support to it rather than just click an option like so: http://s17.postimg.org/l9nhiir3j/Code_Blocks_Compiler_Settings.png )
error: 'std::this_thread' has not been declared
Can you know why
cire wrote:
Use an operating specific function (such as Sleep on Windows) or if you have C++11 support:
It would seem your compiler doesn't support C++11 in it's current configuration.