請問c++時間計算問題

下面是我的code
#include<sstream>
#include<time.h>
#include<iostream>
#include<cstdlib>
#include<fstream>
using namespace std;
const int MAX_FILE = 10000;

int main()
{
unsigned int sum = 0;
for (int n = 0; n < MAX_FILE; ++n)
{
stringstream s;
int value = 0;
float totaltime=0.0;
clock_t start, end;

s << n << ".txt";
//cout << s.str() << endl;
start = time(NULL);
ifstream in(s.str().c_str());
if (!in)
{
// Cannot open file
}
else
{
while (!in.eof())
{
in >> value;
//cout << value;
sum += value;
}
}
in.close();
}
ofstream out("output.txt");
out.close();
end=clock();
cout << "sum=" << sum << endl;
totaltime = (float)(end - start);
cout << "花費時間=" <<totaltime<< endl;
system("pause");
return 0;
}

error C2065: 'start' : 未宣告的識別項
error C2065: 'totaltime' : 未宣告的識別項
IntelliSense: 識別項 "totaltime" 未定義

原本讀寫檔所有都可正常執行
但計算執行時間加了clock_t宣告start,end和clock()之後就不能執行
真的很奇怪,根本沒什錯誤啊
我用vb 2013
我換dev也是一樣= =
請問各位高手這要怎麼處理?
作業都寫出來了,卻卡在這裡...
大家幫幫我
2014-05-26 21:38 發佈
文章關鍵字 問題
看起來是沒宣告變數的型態,手機上看到順手回而已,由於小弟沒寫過c++,有錯請指正
很久沒寫c了,試看看把宣告變數的敘述移到for迴圈上面吧!不要寫在迴圈裡面!

達哥~ wrote:
很久沒寫c了,試看看...(恕刪)

我放到for上面就ok了,感謝你啦!
內文搜尋
X
評分
評分
複製連結
Mobile01提醒您
您目前瀏覽的是行動版網頁
是否切換到電腦版網頁呢?