1

スレッド化の使い方を学ぶための簡単なプログラムを作成しました。これは私が作成したコードです

#include <iostream>
#include <stdlib.h>
#include <thread>

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<=10;ctr++){
        cout<<"First thread: "<<ctr<<endl;
    }
}

void count_desc(){
    int ctr;
    for(ctr=10;ctr>=1;ctr--){
        cout<<"Second thread: "<<ctr<<endl;
    }
}

Dev C++ 5.5.3 を使用しています。これに関する他の質問を読みましたが、プログラミングの初心者である私は高度な指示を実際には理解できません。このコードをコンパイルすると、次のエラーが生成されます

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

Dev C++ のプロジェクト オプションの C++ コンパイラの追加のコマンドライン オプションに -std=c++11 を既に含めましたが、まだエラーを削除できません。私が間違っていることを確認してください。また、他のライブラリを構築するのに苦労しているため、できるだけ他のライブラリの使用を開始したくありません(例:ブースト)

4

1 に答える 1