📄 subject_23019.htm
字号:
<p>
序号:23019 发表者:Zerg 发表日期:2002-11-30 17:16:10
<br>主题:VC++的BUG,也许是我的理解错误.请高手赐教!
<br>内容://///////首先申明我是菜鸟!!!!!!!!!!!!!!!<BR>///////VC++的BUG,也许是我的理解错误。。<BR>//疑惑??!!!?!?!?!?!??!?!?!?!???!?!!<BR>/* #include<iostream><BR><BR>using namespace std;<BR><BR>int main()<BR>{<BR>char hexnum[8];<BR>char temp[8];<BR> cin>>hexnum;<BR>temp = hexnum; //error C2106: '=' : left operand must be l-value <BR> //VC编译通不过<BR> cout<<temp; //支持标准的Dec-C++ 和 Quincy 都可以!!!!!!<BR><BR> return 0; //也许我既然用#include<iostream><BR> // using namespace std;<BR>} //就不该用char,而用string,vector之类<BR>*////////<BR>//下面是一段把16进制转换为10进制的小程序。(如有错误和不妥请狂改!!!)<BR>//疑惑是这样出来的:....................................<BR>//请高手赐教<BR>////////////////////////////////////////////////////////////////////////////<BR>#include<iostream><BR>#include<string><BR>#include<cmath><BR>using namespace std;<BR><BR>int main( )<BR>{<BR> double hex[8];<BR> double dec=0;<BR> char hexnum[8];<BR> int numsize,tempszie;<BR><BR> cout<<"Enter 8 bit Hexadecimal : ";<BR> //cout一个16进制数<BR> cin>>hexnum;<BR><BR> numsize = strlen(hexnum);<BR> tempszie = 8 - numsize;<BR> /////////////////////////////////////////////////////<BR> char temp[8];<BR> //for(int ct=0;ct<8;++ct) //如果这样没错<BR> //temp[ct] = hexnum[ct];<BR> temp = hexnum; //也许是VC的错!!!!!!!!!!!!???????/<BR> //????<BR> //请高手赐教????<BR> if( numsize<8 )<BR> { int m=0;<BR> <BR> for(int n=0; n<8; ++n)<BR> {<BR> if( n < tempszie )<BR> { hexnum[n] = 48; } //我设定的是8位,<BR> //把if(!8)转换为8位<BR> else<BR> { hexnum[n] = temp[m]; <BR> m++;<BR> }<BR> <BR> }<BR><BR> }<BR> <BR> for(int i=0;i<8;++i)<BR> {<BR> <BR> if( hexnum[i]<=57 && hexnum[i]>=48 )<BR> {<BR> <BR> hex[i]=(hexnum[i]-48);<BR> <BR> dec+=( hex[i]*pow(16,7-i) );<BR> }<BR> else if( hexnum[i]<=70 && hexnum[i]>=65 )<BR> {<BR> <BR> hex[i]=(hexnum[i]-55);<BR> <BR> dec+=( hex[i]*pow(16,7-i) );<BR> }<BR> else<BR> {<BR> <BR> hex[i]=(hexnum[i]-87);<BR> <BR> dec+=( hex[i]*pow(16,7-i) );<BR> }<BR><BR> }<BR> cout<<"The number Decimalist is : "<<dec<<endl;<BR> <BR> system("PAUSE"); <BR> return 0;<BR>}<BR>
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:tjhe 回复日期:2002-11-30 19:04:18
<br>内容:char temp[8]中数组名temp为指针常量,不能作为左值。要实现<BR>hexnum数组中对应元素到temp数组的复制,应采用单循环,逐个元素复制。<BR><BR>2002-11-30 19:41:21
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -