【发布时间】:2011-08-26 04:18:50
【问题描述】:
嘿,所以我正在使用 pdCurses 库和 stringStream 来计算并制作一个代表时钟的 5 个字符长的字符串。它显示为 00:00、0:00、00.00 或 0.000。但是,在运行我的函数时,我在这部分得到了一个异常:
if((int)time >= 10)
{
if((int)time >= 60)
{
if((int)time >= 600)
{
异常指向这个也说存在访问冲突:
/* verify block type */
_ASSERTE(_BLOCK_TYPE_IS_VALID(pHead->nBlockUse));
为什么在 if 语句这样简单的事情上会发生这种情况?我该如何解决? 感谢您的帮助! =) 这也是我的功能:
//////////////////////////////////////////// Refresh ///////////////////////////
void Refresh()
{
for(int r = 0;r<nrows;r++)
{
move(r,0);
instr((char*)_contents[r].c_str());
} // make sure this works later
// Insert the current time;
enum{ time_loc_y= 24, time_loc_x= 10 };
long float time = myStopwatch.ElapsedTime();
string time_s= " ";
string min; ss << (int)time%60; ss >> min;
string sec; ss << (int)time/60; ss >> sec;
if((int)time >= 10)
{
if((int)time >= 60)
{
if((int)time >= 600)
{
time_s.insert(0, min); // 00:00
time_s.insert(time_s.begin()+2, ':');
time_s.insert(4, sec);
}
else
{
time_s.insert(1, min); // 0:00
time_s.insert(time_s.begin()+2, ':');
time_s.insert(4, sec);
}
}
else
{
ss.precision(2); ss << time; // 00.00
ss >> time_s;
}
}
else
{
ss.precision(3);
ss << time; // 0.000
ss >> time_s;
}
mvinstr(time_loc_y, time_loc_x, (char*)time_s.c_str());
refresh();
}; // end of function
【问题讨论】:
-
ss的声明是什么,您同时使用 put (<<) 和 get (>>) 运算符? -
首先,
long float是什么?其次,如果ss是stringstream,那么你不能像你使用它的方式连续两次使用ss。第二次尝试将导致读取空字符串。第三,问题很可能是发生在其他地方的堆损坏。您发布的代码不足以查明问题。
标签: c++ exception if-statement double int