我正在尝试在if
语句中的文本文件" Data.txt"中输出距离和时间数据。我知道if
语句中的操作正在执行,因为我可以看到单词" Hello!"和"距离:5次:0"在我的"立即窗口"中打印(使用Visual Studio 2017),但我的文本文件Data.txt是空白的!我任意设置distance = 5和time = 0以使我的代码更容易调试。
//opening data file to write to
ofstream datafile("Data.txt");
if (HandClosedOnTarget(rightHandState, rightHandPosition, targetPositions[currentTargetIndex]))
{
secondsPassed = 0;
distance = 5;
datafile << "time (sec): " << secondsPassed << " distance: " << distance << "\n";
TRACE(L"Hello!\n");
TRACE(L"distance = %s time: %s \n", std::to_wstring(distance).c_str(), std::to_wstring(secondsPassed).c_str());
}
感谢您的帮助!