I don't know how to pause the screen 2

Pages: 12
Apr 30, 2015 at 11:47am
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?
Apr 30, 2015 at 12:07pm
Hi,

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

Hope this helps :+)
Apr 30, 2015 at 1:26pm
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:)
May 5, 2015 at 10:55pm
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?
May 5, 2015 at 11:00pm
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/
May 6, 2015 at 11:20am
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;
}


??
May 6, 2015 at 11:42am
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 May 6, 2015 at 11:43am
May 7, 2015 at 1:22am
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 May 7, 2015 at 1:23am
May 7, 2015 at 1:24am
closed account (2LzbRXSz)
Make sure you
1
2
#include <thread>
#include <chrono> 
May 9, 2015 at 3:21pm
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 ?



May 9, 2015 at 3:41pm
read my post...
May 9, 2015 at 11:04pm
"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 ?

May 10, 2015 at 12:15am
closed account (2LzbRXSz)
What compiler are you using, and does it support C++11?
May 10, 2015 at 12:24am
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.
May 10, 2015 at 12:26am
with the chrono and thread.... that may be very specific to the version of compiler.
May 10, 2015 at 11:43am
"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"




May 10, 2015 at 1:24pm
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:)
May 10, 2015 at 6:56pm
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?
May 10, 2015 at 7:34pm
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.
May 11, 2015 at 12:44am
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