【发布时间】:2009-09-03 03:33:20
【问题描述】:
我正在创建一个简单的 C++ 程序,在主线程中向用户询问华氏温度,然后在另一个线程中将此值转换为摄氏度。
但我继续收到一个错误。这个错误一直存在
visual studio 2008\projects\cs1\cs1\cs1.cpp(16):错误 C2143:语法错误:缺少“;”在'='之前
此问题有时会消失,但不会出现运行时异常。 我使用的是 Visual Studio 2008,Windows XP。
谢谢 -Sunny 耆那教
#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;
}
【问题讨论】:
-
似乎不是一项足够复杂的任务,无法在不同的线程中完成。
标签: c++ multithreading