简单的线程在c ++中工作

0 c++ multithreading

我正在创建一个简单的C++程序来询问用户在主线程中的华氏度,然后在另一个线程中将此值转换为Celsius.

但我继续得到一个错误.此错误保持不变

visual studio 2008\projects\cs1\cs1\cs1.cpp(16):错误C2143:语法错误:缺少';' 在'='之前

此问题有时会消失,但不会出现运行时异常.我正在使用Visual Studio 2008,Windows XP.

谢谢-Sunny Jain

#include "stdafx.h"
#include "stdafx.h"
#include "windows.h"
#include "stdlib.h"
#include "stdio.h"
#include "process.h"
#include "conio.h"
#include "iostream"
using namespace std;

bool flag= false;

void calculateTemperature_DegreeCelcius(void * Fahrenheit)
{
    float far;
    far=*((float*) Fahrenheit);
    float celcius = (5.0/9.0)*(far - 32);
    cout << "\nDegree Celcius :";
    cout << celcius;  
    flag = true;
}


int _tmain(int argc, _TCHAR* argv[])
{
    float temp_Fahrenheit;

    while(true){
        cout << "\nEnter Degree Fahrenheit value you want to convert to Degree Celcius\n";
        cout << "Degree Fahrenheit :";     
        cin >> temp_Fahrenheit;
        _beginthread(calculateTemperature_DegreeCelcius, 0, &temp_Fahrenheit);
    while(true){
        if(flag==false){
            Sleep(200);
        } else {
            break;
        }
    }

    char *command = (char *)NULL;
    cout<< "\nDo you want to continue ? yes/no :";
    cin>> command;

    if (strcmp("yes",command)){
        flag = false;
    } else {
        break;
    }
    }
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

pli*_*nth 12

在许多C/C++编译器中,尤其是Microsoft编译器,远远是保留字(关键字或在标题中定义).


M1E*_*1EK 6

far是WinDef.h中的#define

#define far
#define near
#if (!defined(_MAC)) && ((_MSC_VER >= 800) || defined(_STDCALL_SUPPORTED))
#define pascal __stdcall
#else
#define pascal
#endif
Run Code Online (Sandbox Code Playgroud)