I don't know how to pause the screen 2

Pages: 12
I read this http://www.cplusplus.com/forum/general/18/

none of the so called solutions in the link work .

I have windows and I would like to pause the screen without getting

press a key to continue... message

so how is it possible?
Hi,

On the Beginners Board, read the Topic Console closing down - it is stickied.

Hope this helps :+)
closed account (2LzbRXSz)
Hi, I believe what you're looking for is the sleep_for function.
http://www.cplusplus.com/reference/thread/this_thread/sleep_for/

Honestly, using system functions aren't really recommended, so if you can avoid them that's your best bet.

Plus, system functions are platform specific. sleep_for isn't:)
I read about it but I could not understand how to use sleep_for() properly along with its syntax . It is somehow complicated for me so can you please tell me how to use it properly with an example?
closed account (2LzbRXSz)
Sure :)

1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
#include <thread>
#include <chrono>

int main()
{
    std::this_thread::sleep_for(std::chrono::seconds(5));
    std::cout << "Hello, world!" << std::endl;
    
    return 0;
}


I've actually used it in a typewriter function I posted on this thread
http://www.cplusplus.com/forum/lounge/159955/
thank you very much . I already read it . However , I am using

using namespace std ;

so it becomes like this ???

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include <thread>
#include <chrono>

using namespace std;

int main()
{
    this_thread sleep_for(chrono seconds(5));
    cout << "Hello, world!" << endl;
    
    return 0;
}


??
no. It becomes this:
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include <thread>
#include <chrono>

using namespace std;

int main()
{
    this_thread::sleep_for(chrono::seconds(5));
    cout << "Hello, world!" << endl;
    
    return 0;
}


read about namespace resolution. you're using the std namespace so you can omit that, but that's all, you still have to scope the other stuff on your line 9.

also it's best not to use:
using namespace std;
Last edited on
when I run your code I got many errors :

this_thread has not been declared

chrono has not been declared

sleep_for has not been declared

seconds undeclared (first use this function)

what are the meaning of these errors and how to correct them so that when I run your code I do not get errors again??
Last edited on
closed account (2LzbRXSz)
Make sure you
1
2
#include <thread>
#include <chrono> 
this is the code you gave me

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include <thread>
#include <chrono>

using namespace std;

int main()
{
    this_thread::sleep_for(chrono::seconds(5));
    cout << "Hello, world!" << endl;
    
    return 0;
}



and as you can see ,

1
2
#include <thread>
#include <chrono> 


are included . However when I run it your code , I got these errors:


this_thread has not been declared

chrono has not been declared

sleep_for has not been declared

seconds undeclared (first use this function)

and now ?



read my post...
"also it's best not to use:
using namespace std;"

I want to use your code only with using namespace std;

you gave me a code with using namespace std;

"no. It becomes this:


1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include <thread>
#include <chrono>

using namespace std;

int main()
{
    this_thread::sleep_for(chrono::seconds(5));
    cout << "Hello, world!" << endl;
    
    return 0;
}
"

However when I run it , I got these errors :

this_thread has not been declared

chrono has not been declared

sleep_for has not been declared

seconds undeclared (first use this function)

So the code you gave me with using namespace std; has errors . What is the source of these errors and how to correct them ?

closed account (2LzbRXSz)
What compiler are you using, and does it support C++11?
you want to start your program with debugging. In my compiler it is F5.
Ctrl+F5 is to start without debugging. in visual studio you will see this in the debug drop down tab.
with the chrono and thread.... that may be very specific to the version of compiler.
"What compiler are you using, and does it support C++11? "

I am using Dev C++ . Could you please tell me how to know if Dev C++ supports C++ 11 ??

in Dev C++ , the debugging is started using F8 . When I use the debugging , it says :"project is not compiled"

How to fix this error?

"with the chrono and thread.... that may be very specific to the version of compiler."

the version of my Dev C++ is 4.9.9.2 . When I compiled the code above it says :" thread no such file or directory" , "chrono no such file or directory"




closed account (2LzbRXSz)
I Googled it, and people using DevC++ have had trouble with C++11 features. This second answer shows how to change it to C++11 (incase it's not already set that way).
http://stackoverflow.com/questions/20432507/orwell-dev-c-doesnt-work-with-c11

The project is not compiled error is fixed by compiling the project - which, you can't do until you've fixed the errors.

If this doesn't work, there's probably more that could be done to fix the problem, and I'll try my best to help:)
Thank you for your reply

I read the information in the link you provided me . It is mentioned the following:



If you want to use C++11 in Dev-C++ you should to this steps:

Go to Tools > Compiler Options
Go to the tab Settings > Code Generation
Change the parameter Language Standard (-std) to ISO C++11

However , when I went to Code Generation in the Settings tab , I did not find the parameter Language Standard . I found only the following parameters:

1) enable exception handling

2)use the same size for double and float

3)put extra commentary information in the generated

4)generate instructions for the following machine

5)enable use of processor specific built in functions

so what to do now?
closed account (2LzbRXSz)
Well, I've never used DevC++, so I'm kind of relying on Google here.

Ah! I think I've found your problem - http://www.cplusplus.com/forum/beginner/134464/

You're using 4.9.9.2, which is outdated. You just need to download a different version of it.
I downloaded the latest version of Dev C++ namely Dev-Cpp 5.11 . Then I tried to run the code above :

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include <thread>
#include <chrono>

using namespace std;

int main()
{
    this_thread::sleep_for(chrono::seconds(5));
    cout << "Hello, world!" << endl;
    
    return 0;
}


but , this time I got this error:

#ifndef _CXX0X_WARNING_H
#define _CXX0X_WARNING_H 1

#if __cplusplus < 201103L
#error This file requires compiler and library support for the \
ISO C++ 2011 standard. This support is currently experimental, and must be \
enabled with the -std=c++11 or -std=gnu++11 compiler options.
#endif

#endif


So I followed the instructions in the link you provided me :


Go to Tools > Compiler Options
Go to the tab Settings > Code Generation
Change the parameter Language Standard (-std) to ISO C++11

and I found the language standard (-std) parameter and change it to ISO C++11 . However , when I run the code above again , I got the same error again:

#error This file requires compiler and library support for the \
ISO C++ 2011 standard. This support is currently experimental, and must be \
enabled with the -std=c++11 or -std=gnu++11 compiler options.
#endif



I do not know how to solve this problem
Pages: 12