我正在將代碼從Linux移植到Window。C++ 11 chrono in visual studio 2013
而且我沒有想到在使用std :: chrono時會出現一個錯誤。
因爲std :: chrono是C++標準庫,我預計它在未經修改的情況下工作。
下面是顯示錯誤的代碼。
錯誤發生在我使用運算符的持續時間實例和duration_cast函數with no instance of function template
的部分。
,代碼工作正常
std::string ChronoTimer::currentTime(){
using namespace std::chrono;
auto now = system_clock::now();
time_point<system_clock> epoch;
microseconds ms = duration_cast<milliseconds>(now - epoch);
hours hour = duration_cast<hours>((ms % hours(24)) + hours(9));
minutes min = duration_cast<minutes>(ms % hours(1));
seconds sec = duration_cast<seconds>(ms % minutes(1));
milliseconds msec = duration_cast<milliseconds>(ms % seconds(1));
std::stringstream strStream;
strStream << std::setfill('0') << std::setw(2) << hour.count() << ":";
strStream << std::setfill('0') << std::setw(2) << min.count() << ":";
strStream << std::setfill('0') << std::setw(2) << sec.count() << ".";
strStream << std::setfill('0') << std::setw(3)<< msec.count();
return strStream.str();
}
1 IntelliSense: no instance of function template "std::chrono::duration_cast" matches the argument list
argument types are: (<error-type>)
2 IntelliSense: no operator "+" matches these operands
operand types are: std::chrono::system_clock::rep + std::chrono::hours
3 IntelliSense: no instance of function template "std::chrono::duration_cast" matches the argument list
argument types are: (std::chrono::system_clock::rep)
如何向我們展示**實際的錯誤信息**? (並且在你發佈的代碼中清楚地標明它出現的位置) –
你得到的錯誤是什麼? – Zacrath
對不起,我添加內容 – SangminKim