Note that there are some explanatory texts on larger screens.

plurals
  1. PODev C++ simple threading program
    primarykey
    data
    text
    <p>I created a simple program to learn how to use threading. This is the code i created</p> <pre><code>#include &lt;iostream&gt; #include &lt;stdlib.h&gt; #include &lt;thread&gt; using namespace std; void count_asc(); void count_desc(); int main() { thread first(count_asc); thread second(count_desc); first.join(); second.join(); system("pause"); return 0; } void count_asc(){ int ctr; for(ctr=1;ctr&lt;=10;ctr++){ cout&lt;&lt;"First thread: "&lt;&lt;ctr&lt;&lt;endl; } } void count_desc(){ int ctr; for(ctr=10;ctr&gt;=1;ctr--){ cout&lt;&lt;"Second thread: "&lt;&lt;ctr&lt;&lt;endl; } } </code></pre> <p>I am using Dev C++ 5.5.3. I have read other questions about this but me being a beginner in programming cannot really understand advanced instructions. When this code is compiled the following error is produced</p> <pre><code>main.cpp: In function 'int main()': main.cpp:11:2: error: 'thread' was not declared in this scope main.cpp:11:9: error: expected ';' before 'first' main.cpp:12:9: error: expected ';' before 'second' main.cpp:14:2: error: 'first' was not declared in this scope main.cpp:15:2: error: 'second' was not declared in this scope </code></pre> <p>I have already included -std=c++11 in the c++ compiler additional command-line options in the project option of the Dev C++ but i can't still remove the errors. Can you please check what i am doing wrong? also as much as possible i dont want to start using other libraries as i am having a hard time building them(ex. boost)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload