|
代码如下:
//波特率
int index_sel = m_bo.GetCurSel();
char temp_str[10] = "";
m_bo.GetLBText(index_sel,temp_str);
int bo = atoi(temp_str);
//奇偶校验位
int pority = m_pority.GetCurSel();
//数据位
index_sel = m_data.GetCurSel();
memset(temp_str,0,10);
m_data.GetLBText(index_sel,temp_str);
int bytebit = atoi(temp_str);
//停止位
index_sel = m_stopbit.GetCurSel();
memset(temp_str,0,10);
m_stopbit.GetLBText(index_sel,temp_str);
int stopbit = 0;
if(temp_str == "1")
stopbit = ONESTOPBIT;
else if(temp_str == "1.5")
stopbit = ONE5STOPBITS;
else if(temp_str == "2")
stopbit = TWOSTOPBITS;
前面都对。
调试时,发现temp_str="1",
可是经过下面这段代码时,
if(temp_str == "1")
stopbit = ONESTOPBIT;
else if(temp_str == "1.5")
stopbit = ONE5STOPBITS;
else if(temp_str == "2")
stopbit = TWOSTOPBITS;
都跳过去了。按理说应该是
stopbit = ONESTOPBIT;
可都跳过去了,stopbit=0.
这是怎么回事?请高手指教,谢谢!
很有意思的问题欸
你看看这个,我去网上查了一下,这个“==”好像对于字符数组来说,只会比对地址,比较的并不是字符串内容,所以说,要比较字符串还是用strcmp这一类函数。或者自己重载一个“==”。非常感谢您的问题,又发现了小细节。
|
上一篇: 无法启动程序"D\VC\Study\2\test\debug\test.ocx下一篇: 在静态文本上显示文字的问题
|