??xml version="1.0" encoding="utf-8" standalone="yes"?>久久这里只有精品首页,日韩精品久久久久久久电影蜜臀 ,亚洲婷婷国产精品电影人久久http://m.shnenglu.com/zzfmars/category/14325.html明天是另一天,你能看到明天的太阛_Q?/description>zh-cnSat, 28 May 2011 12:06:44 GMTSat, 28 May 2011 12:06:44 GMT60getlineQ) 函数http://m.shnenglu.com/zzfmars/archive/2011/05/27/147447.htmlKevin_ZhangKevin_ZhangFri, 27 May 2011 15:50:00 GMThttp://m.shnenglu.com/zzfmars/archive/2011/05/27/147447.htmlhttp://m.shnenglu.com/zzfmars/comments/147447.htmlhttp://m.shnenglu.com/zzfmars/archive/2011/05/27/147447.html#Feedback0http://m.shnenglu.com/zzfmars/comments/commentRss/147447.htmlhttp://m.shnenglu.com/zzfmars/services/trackbacks/147447.html// test3.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include 
"iostream"
#include 
"string"
#include 
"stdio.h"


using namespace std;


int main(int argc, char* argv[])
{   
    
    
string str1,str2,str3;
    getline(cin,str1);
    getline(cin,str2);
    str3
=str1+str2;
    cout
<<str1<<endl<<str2<<endl<<str3<<endl;
    cout
<<str1[0]<<endl<<str2[0]<<endl;
    
return 0;
}



Kevin_Zhang 2011-05-27 23:50 发表评论
]]>
动态创建整形数l?/title><link>http://m.shnenglu.com/zzfmars/archive/2011/05/27/147415.html</link><dc:creator>Kevin_Zhang</dc:creator><author>Kevin_Zhang</author><pubDate>Fri, 27 May 2011 13:52:00 GMT</pubDate><guid>http://m.shnenglu.com/zzfmars/archive/2011/05/27/147415.html</guid><wfw:comment>http://m.shnenglu.com/zzfmars/comments/147415.html</wfw:comment><comments>http://m.shnenglu.com/zzfmars/archive/2011/05/27/147415.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.shnenglu.com/zzfmars/comments/commentRss/147415.html</wfw:commentRss><trackback:ping>http://m.shnenglu.com/zzfmars/services/trackbacks/147415.html</trackback:ping><description><![CDATA[<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><img align="top" src="http://m.shnenglu.com/images/OutliningIndicators/None.gif" alt="" /><span style="color: #008000">//</span><span style="color: #008000"> test3.cpp : Defines the entry point for the console application.<br /><img align="top" src="http://m.shnenglu.com/images/OutliningIndicators/None.gif" alt="" /></span><span style="color: #008000">//<br /><img align="top" src="http://m.shnenglu.com/images/OutliningIndicators/None.gif" alt="" /></span><span style="color: #000000">#include </span><span style="color: #000000">"</span><span style="color: #000000">stdafx.h</span><span style="color: #000000">"</span><span style="color: #000000"><br /><img align="top" src="http://m.shnenglu.com/images/OutliningIndicators/None.gif" alt="" />#include </span><span style="color: #000000">"</span><span style="color: #000000">iostream</span><span style="color: #000000">"</span><span style="color: #000000"><br /><img align="top" src="http://m.shnenglu.com/images/OutliningIndicators/None.gif" alt="" /></span><span style="color: #0000ff">using</span><span style="color: #000000"> </span><span style="color: #0000ff">namespace</span><span style="color: #000000"> std;<br /><img align="top" src="http://m.shnenglu.com/images/OutliningIndicators/None.gif" alt="" /><br /><img align="top" src="http://m.shnenglu.com/images/OutliningIndicators/None.gif" alt="" /><br /><img align="top" src="http://m.shnenglu.com/images/OutliningIndicators/None.gif" alt="" /></span><span style="color: #0000ff">int</span><span style="color: #000000"> main(</span><span style="color: #0000ff">int</span><span style="color: #000000"> argc, </span><span style="color: #0000ff">char</span><span style="color: #000000">*</span><span style="color: #000000"> argv[])<br /><img id="Codehighlighter1_167_386_Open_Image" onclick="this.style.display='none'; Codehighlighter1_167_386_Open_Text.style.display='none'; Codehighlighter1_167_386_Closed_Image.style.display='inline'; Codehighlighter1_167_386_Closed_Text.style.display='inline';" align="top" src="http://m.shnenglu.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_167_386_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_167_386_Closed_Text.style.display='none'; Codehighlighter1_167_386_Open_Image.style.display='inline'; Codehighlighter1_167_386_Open_Text.style.display='inline';" align="top" src="http://m.shnenglu.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_167_386_Closed_Text"><img src="http://m.shnenglu.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_167_386_Open_Text"><span style="color: #000000">{   <br /><img align="top" src="http://m.shnenglu.com/images/OutliningIndicators/InBlock.gif" alt="" />    </span><span style="color: #0000ff">int</span><span style="color: #000000"> length,i,</span><span style="color: #000000">*</span><span style="color: #000000"> ptr1;<br /><img align="top" src="http://m.shnenglu.com/images/OutliningIndicators/InBlock.gif" alt="" />    cout</span><span style="color: #000000"><<</span><span style="color: #000000">"</span><span style="color: #000000">误入数l的长度Q?/span><span style="color: #000000">"</span><span style="color: #000000">;<br /><img align="top" src="http://m.shnenglu.com/images/OutliningIndicators/InBlock.gif" alt="" />    cin</span><span style="color: #000000">>></span><span style="color: #000000">length;<br /><img align="top" src="http://m.shnenglu.com/images/OutliningIndicators/InBlock.gif" alt="" />    ptr1</span><span style="color: #000000">=</span><span style="color: #0000ff">new</span><span style="color: #000000"> </span><span style="color: #0000ff">int</span><span style="color: #000000">[length];<br /><img align="top" src="http://m.shnenglu.com/images/OutliningIndicators/InBlock.gif" alt="" />    </span><span style="color: #0000ff">for</span><span style="color: #000000">(i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;i</span><span style="color: #000000"><</span><span style="color: #000000">length;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /><img align="top" src="http://m.shnenglu.com/images/OutliningIndicators/InBlock.gif" alt="" />        </span><span style="color: #000000">*</span><span style="color: #000000">(ptr1</span><span style="color: #000000">+</span><span style="color: #000000">i)</span><span style="color: #000000">=</span><span style="color: #000000">i</span><span style="color: #000000">*</span><span style="color: #000000">10</span><span style="color: #000000">;<br /><img align="top" src="http://m.shnenglu.com/images/OutliningIndicators/InBlock.gif" alt="" />    </span><span style="color: #0000ff">for</span><span style="color: #000000">(i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;i</span><span style="color: #000000"><</span><span style="color: #000000">length;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /><img align="top" src="http://m.shnenglu.com/images/OutliningIndicators/InBlock.gif" alt="" />        cout</span><span style="color: #000000"><<</span><span style="color: #000000">ptr1[i]</span><span style="color: #000000"><<</span><span style="color: #000000">"</span><span style="color: #000000"> </span><span style="color: #000000">"</span><span style="color: #000000">;<br /><img align="top" src="http://m.shnenglu.com/images/OutliningIndicators/InBlock.gif" alt="" />    cout</span><span style="color: #000000"><<</span><span style="color: #000000">endl;<br /><img align="top" src="http://m.shnenglu.com/images/OutliningIndicators/InBlock.gif" alt="" />    delete[] ptr1;<br /><img align="top" src="http://m.shnenglu.com/images/OutliningIndicators/InBlock.gif" alt="" />    </span><span style="color: #0000ff">return</span><span style="color: #000000"> </span><span style="color: #000000">0</span><span style="color: #000000">;<br /><img align="top" src="http://m.shnenglu.com/images/OutliningIndicators/ExpandedBlockEnd.gif" alt="" />}</span></span><span style="color: #000000"><br /><img align="top" src="http://m.shnenglu.com/images/OutliningIndicators/None.gif" alt="" /></span></div><img src ="http://m.shnenglu.com/zzfmars/aggbug/147415.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.shnenglu.com/zzfmars/" target="_blank">Kevin_Zhang</a> 2011-05-27 21:52 <a href="http://m.shnenglu.com/zzfmars/archive/2011/05/27/147415.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>指针操作二维数组http://m.shnenglu.com/zzfmars/archive/2011/05/27/147412.htmlKevin_ZhangKevin_ZhangFri, 27 May 2011 13:44:00 GMThttp://m.shnenglu.com/zzfmars/archive/2011/05/27/147412.htmlhttp://m.shnenglu.com/zzfmars/comments/147412.htmlhttp://m.shnenglu.com/zzfmars/archive/2011/05/27/147412.html#Feedback0http://m.shnenglu.com/zzfmars/comments/commentRss/147412.htmlhttp://m.shnenglu.com/zzfmars/services/trackbacks/147412.html    从键盘输入一?X3的整数矩阵,输出该矩阵ƈ求出d角线元素的和?br />
源代码:
// test3.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include 
"iostream"
using namespace std;


int main(int argc, char* argv[])
{   
    
int a[3][3],i,j,s=0;
    
int (* ptr)[3];
    ptr
=a;
    cout
<<"误入矩늚|";
    
for(i=0;i<3;i++)
        
for(j=0;j<3;j++)
        
{
           cin
>>*(*(ptr+i)+j);
           
if(i==j)
               s
+=*(*(ptr+i)+j);

        }

        cout
<<"输出矩阵Q\n";
        
for(i=0;i<3;i++)
        
{
            
for(j=0;j<3;j++)
                cout
<<ptr[i][j]<<" ";
            cout
<<endl;

        
        }

        cout
<<"矩阵d角线元素的和为:"<<s<<endl;
    
return 0;
}





Kevin_Zhang 2011-05-27 21:44 发表评论
]]>
指针操作一l数l?/title><link>http://m.shnenglu.com/zzfmars/archive/2011/05/27/147407.html</link><dc:creator>Kevin_Zhang</dc:creator><author>Kevin_Zhang</author><pubDate>Fri, 27 May 2011 13:30:00 GMT</pubDate><guid>http://m.shnenglu.com/zzfmars/archive/2011/05/27/147407.html</guid><wfw:comment>http://m.shnenglu.com/zzfmars/comments/147407.html</wfw:comment><comments>http://m.shnenglu.com/zzfmars/archive/2011/05/27/147407.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.shnenglu.com/zzfmars/comments/commentRss/147407.html</wfw:commentRss><trackback:ping>http://m.shnenglu.com/zzfmars/services/trackbacks/147407.html</trackback:ping><description><![CDATA[用指针操作数l。要求先输出数组Q然后将数组倒置Q再输出倒置的数l?br />源代码: <div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><img alt="" align="top" src="http://m.shnenglu.com/images/OutliningIndicators/None.gif" /><span style="color: #008000">//</span><span style="color: #008000"> test3.cpp : Defines the entry point for the console application.<br /><img alt="" align="top" src="http://m.shnenglu.com/images/OutliningIndicators/None.gif" /></span><span style="color: #008000">//<br /><img alt="" align="top" src="http://m.shnenglu.com/images/OutliningIndicators/None.gif" /></span><span style="color: #000000">#include </span><span style="color: #000000">"</span><span style="color: #000000">stdafx.h</span><span style="color: #000000">"</span><span style="color: #000000"><br /><img alt="" align="top" src="http://m.shnenglu.com/images/OutliningIndicators/None.gif" />#include </span><span style="color: #000000">"</span><span style="color: #000000">iostream</span><span style="color: #000000">"</span><span style="color: #000000"><br /><img alt="" align="top" src="http://m.shnenglu.com/images/OutliningIndicators/None.gif" /></span><span style="color: #0000ff">using</span><span style="color: #000000"> </span><span style="color: #0000ff">namespace</span><span style="color: #000000"> std;<br /><img alt="" align="top" src="http://m.shnenglu.com/images/OutliningIndicators/None.gif" /><br /><img alt="" align="top" src="http://m.shnenglu.com/images/OutliningIndicators/None.gif" /><br /><img alt="" align="top" src="http://m.shnenglu.com/images/OutliningIndicators/None.gif" /></span><span style="color: #0000ff">int</span><span style="color: #000000"> main(</span><span style="color: #0000ff">int</span><span style="color: #000000"> argc, </span><span style="color: #0000ff">char</span><span style="color: #000000">*</span><span style="color: #000000"> argv[])<br /><img id="Codehighlighter1_167_476_Open_Image" onclick="this.style.display='none'; Codehighlighter1_167_476_Open_Text.style.display='none'; Codehighlighter1_167_476_Closed_Image.style.display='inline'; Codehighlighter1_167_476_Closed_Text.style.display='inline';" align="top" src="http://m.shnenglu.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_167_476_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_167_476_Closed_Text.style.display='none'; Codehighlighter1_167_476_Open_Image.style.display='inline'; Codehighlighter1_167_476_Open_Text.style.display='inline';" align="top" src="http://m.shnenglu.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_167_476_Closed_Text"><img alt="" src="http://m.shnenglu.com/Images/dot.gif" /></span><span id="Codehighlighter1_167_476_Open_Text"><span style="color: #000000">{   <br /><img alt="" align="top" src="http://m.shnenglu.com/images/OutliningIndicators/InBlock.gif" />    </span><span style="color: #0000ff">int</span><span style="color: #000000"> </span><span style="color: #000000">*</span><span style="color: #000000">ptr1,</span><span style="color: #000000">*</span><span style="color: #000000">ptr2,t;<br /><img id="Codehighlighter1_204_225_Open_Image" onclick="this.style.display='none'; Codehighlighter1_204_225_Open_Text.style.display='none'; Codehighlighter1_204_225_Closed_Image.style.display='inline'; Codehighlighter1_204_225_Closed_Text.style.display='inline';" align="top" src="http://m.shnenglu.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_204_225_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_204_225_Closed_Text.style.display='none'; Codehighlighter1_204_225_Open_Image.style.display='inline'; Codehighlighter1_204_225_Open_Text.style.display='inline';" align="top" src="http://m.shnenglu.com/images/OutliningIndicators/ContractedSubBlock.gif">    </span><span style="color: #0000ff">int</span><span style="color: #000000"> a[]</span><span style="color: #000000">=</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_204_225_Closed_Text"><img alt="" src="http://m.shnenglu.com/Images/dot.gif" /></span><span id="Codehighlighter1_204_225_Open_Text"><span style="color: #000000">{</span><span style="color: #000000">1</span><span style="color: #000000">,</span><span style="color: #000000">2</span><span style="color: #000000">,</span><span style="color: #000000">3</span><span style="color: #000000">,</span><span style="color: #000000">4</span><span style="color: #000000">,</span><span style="color: #000000">5</span><span style="color: #000000">,</span><span style="color: #000000">6</span><span style="color: #000000">,</span><span style="color: #000000">7</span><span style="color: #000000">,</span><span style="color: #000000">8</span><span style="color: #000000">,</span><span style="color: #000000">9</span><span style="color: #000000">,</span><span style="color: #000000">10</span><span style="color: #000000">}</span></span><span style="color: #000000">;<br /><img alt="" align="top" src="http://m.shnenglu.com/images/OutliningIndicators/InBlock.gif" />    ptr1</span><span style="color: #000000">=</span><span style="color: #000000">a;<br /><img alt="" align="top" src="http://m.shnenglu.com/images/OutliningIndicators/InBlock.gif" />    ptr2</span><span style="color: #000000">=&</span><span style="color: #000000">a[</span><span style="color: #000000">9</span><span style="color: #000000">];<br /><img alt="" align="top" src="http://m.shnenglu.com/images/OutliningIndicators/InBlock.gif" />    </span><span style="color: #0000ff">for</span><span style="color: #000000">(</span><span style="color: #0000ff">int</span><span style="color: #000000"> i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;i</span><span style="color: #000000"><</span><span style="color: #000000">10</span><span style="color: #000000">;i</span><span style="color: #000000">++</span><span style="color: #000000">)<br /><img alt="" align="top" src="http://m.shnenglu.com/images/OutliningIndicators/InBlock.gif" />        cout</span><span style="color: #000000"><<*</span><span style="color: #000000">(ptr1</span><span style="color: #000000">+</span><span style="color: #000000">i)</span><span style="color: #000000"><<</span><span style="color: #000000">"</span><span style="color: #000000"> </span><span style="color: #000000">"</span><span style="color: #000000">;<br /><img alt="" align="top" src="http://m.shnenglu.com/images/OutliningIndicators/InBlock.gif" />    cout</span><span style="color: #000000"><<</span><span style="color: #000000">endl;<br /><img alt="" align="top" src="http://m.shnenglu.com/images/OutliningIndicators/InBlock.gif" />    </span><span style="color: #0000ff">while</span><span style="color: #000000">(ptr2</span><span style="color: #000000">></span><span style="color: #000000">ptr1)<br /><img id="Codehighlighter1_329_389_Open_Image" onclick="this.style.display='none'; Codehighlighter1_329_389_Open_Text.style.display='none'; Codehighlighter1_329_389_Closed_Image.style.display='inline'; Codehighlighter1_329_389_Closed_Text.style.display='inline';" align="top" src="http://m.shnenglu.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_329_389_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_329_389_Closed_Text.style.display='none'; Codehighlighter1_329_389_Open_Image.style.display='inline'; Codehighlighter1_329_389_Open_Text.style.display='inline';" align="top" src="http://m.shnenglu.com/images/OutliningIndicators/ContractedSubBlock.gif">    </span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_329_389_Closed_Text"><img alt="" src="http://m.shnenglu.com/Images/dot.gif" /></span><span id="Codehighlighter1_329_389_Open_Text"><span style="color: #000000">{<br /><img alt="" align="top" src="http://m.shnenglu.com/images/OutliningIndicators/InBlock.gif" />        t</span><span style="color: #000000">=*</span><span style="color: #000000">ptr1;<br /><img alt="" align="top" src="http://m.shnenglu.com/images/OutliningIndicators/InBlock.gif" />        </span><span style="color: #000000">*</span><span style="color: #000000">ptr1</span><span style="color: #000000">=*</span><span style="color: #000000">ptr2;<br /><img alt="" align="top" src="http://m.shnenglu.com/images/OutliningIndicators/InBlock.gif" />        </span><span style="color: #000000">*</span><span style="color: #000000">ptr2</span><span style="color: #000000">=</span><span style="color: #000000">t;<br /><img alt="" align="top" src="http://m.shnenglu.com/images/OutliningIndicators/InBlock.gif" />        ptr1</span><span style="color: #000000">++</span><span style="color: #000000">;<br /><img alt="" align="top" src="http://m.shnenglu.com/images/OutliningIndicators/InBlock.gif" />        ptr2</span><span style="color: #000000">--</span><span style="color: #000000">;<br /><img alt="" align="top" src="http://m.shnenglu.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" />    }</span></span><span style="color: #000000"><br /><img alt="" align="top" src="http://m.shnenglu.com/images/OutliningIndicators/InBlock.gif" />    ptr1</span><span style="color: #000000">=&</span><span style="color: #000000">a[</span><span style="color: #000000">0</span><span style="color: #000000">];<br /><img alt="" align="top" src="http://m.shnenglu.com/images/OutliningIndicators/InBlock.gif" />    </span><span style="color: #0000ff">for</span><span style="color: #000000">(</span><span style="color: #0000ff">int</span><span style="color: #000000"> j</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;j</span><span style="color: #000000"><</span><span style="color: #000000">10</span><span style="color: #000000">;j</span><span style="color: #000000">++</span><span style="color: #000000">)<br /><img alt="" align="top" src="http://m.shnenglu.com/images/OutliningIndicators/InBlock.gif" />        cout</span><span style="color: #000000"><<</span><span style="color: #000000">ptr1[j]</span><span style="color: #000000"><<</span><span style="color: #000000">"</span><span style="color: #000000"> </span><span style="color: #000000">"</span><span style="color: #000000">;<br /><img alt="" align="top" src="http://m.shnenglu.com/images/OutliningIndicators/InBlock.gif" />    cout</span><span style="color: #000000"><<</span><span style="color: #000000">endl;<br /><img alt="" align="top" src="http://m.shnenglu.com/images/OutliningIndicators/InBlock.gif" />    </span><span style="color: #0000ff">return</span><span style="color: #000000"> </span><span style="color: #000000">0</span><span style="color: #000000">;<br /><img alt="" align="top" src="http://m.shnenglu.com/images/OutliningIndicators/ExpandedBlockEnd.gif" />}</span></span><span style="color: #000000"><br /><img alt="" align="top" src="http://m.shnenglu.com/images/OutliningIndicators/None.gif" /></span></div><img border="0" alt="" src="http://m.shnenglu.com/images/cppblog_com/zzfmars/369.jpg" width="667" longdesc="" height="437" /><br /><img src ="http://m.shnenglu.com/zzfmars/aggbug/147407.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.shnenglu.com/zzfmars/" target="_blank">Kevin_Zhang</a> 2011-05-27 21:30 <a href="http://m.shnenglu.com/zzfmars/archive/2011/05/27/147407.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>用scanf输入字符串空g识别Q?http://m.shnenglu.com/zzfmars/archive/2011/05/08/145930.htmlKevin_ZhangKevin_ZhangSun, 08 May 2011 02:22:00 GMThttp://m.shnenglu.com/zzfmars/archive/2011/05/08/145930.htmlhttp://m.shnenglu.com/zzfmars/comments/145930.htmlhttp://m.shnenglu.com/zzfmars/archive/2011/05/08/145930.html#Feedback0http://m.shnenglu.com/zzfmars/comments/commentRss/145930.htmlhttp://m.shnenglu.com/zzfmars/services/trackbacks/145930.html用scanf不是不显C空| 而是用scanf接收字符串的话, 在串首遇到空格的话,跌Ql寻找下一个非I格字符Q? 在串中遇到空格时Q结束字W串的输入? 所以如果用戯? abcd efg"的话Q? scanf取得的字W串?abcd"? 而gets取得字符串时Q是在遇到EOF(串尾)时停止,所以不存在q个问题?/pre>
控制W不?你用%c说明是输入一个字W? 此时可以scanf可以接受I格  
但其他控制符都以I格为结束标??d %s都是以空gؓl束 所以你的二个不接受I格
 
 
ȝQscanf 接受字符Ԍ遇到I格l束Q即以空gؓl束W?/pre>
     printf 输出字符Ԍ遇到I格不结束,而是遇到'\0'q个字符串结束标志才l束?/pre>
     因此Z处理方便Q输入字W串?scanf和gets永远分开使用?/pre>
 
 


Kevin_Zhang 2011-05-08 10:22 发表评论
]]>I格字符和字W串l束字符的区?http://m.shnenglu.com/zzfmars/archive/2011/05/08/145929.htmlKevin_ZhangKevin_ZhangSun, 08 May 2011 02:08:00 GMThttp://m.shnenglu.com/zzfmars/archive/2011/05/08/145929.htmlhttp://m.shnenglu.com/zzfmars/comments/145929.htmlhttp://m.shnenglu.com/zzfmars/archive/2011/05/08/145929.html#Feedback0http://m.shnenglu.com/zzfmars/comments/commentRss/145929.htmlhttp://m.shnenglu.com/zzfmars/services/trackbacks/145929.html
字符串结束字W?\0  ASCII ?0
I格你看不到。ASCII ?32 
字符串结束字W?\0 ASCII ?0x00
I格。ASCII ?0x20 
 
 


Kevin_Zhang 2011-05-08 10:08 发表评论
]]>
字符串输入时应注意的问题http://m.shnenglu.com/zzfmars/archive/2010/11/22/134309.htmlKevin_ZhangKevin_ZhangMon, 22 Nov 2010 13:11:00 GMThttp://m.shnenglu.com/zzfmars/archive/2010/11/22/134309.htmlhttp://m.shnenglu.com/zzfmars/comments/134309.htmlhttp://m.shnenglu.com/zzfmars/archive/2010/11/22/134309.html#Feedback0http://m.shnenglu.com/zzfmars/comments/commentRss/134309.htmlhttp://m.shnenglu.com/zzfmars/services/trackbacks/134309.htmlscanf()Qgetch()Qgetchar()Qgets()Qgetline()。这些函数都是实C键盘输入的标准输入方式。但是却有一些区别:
gets()函数用来从标准输入设?键盘)d字符串直到回车结? 但回车符不属于这个字W串Q其中字W串中可以有I字W。例?
   char  s[50];
   gets(s); 
scanf("%s", &s)?gets(s)函数怼, 但不完全相同, 使用scanf("%s", &s)函数输入字符串时存在一个问? 是如果输入了空g认ؓ输入字符串结?I格后的字符作Z一个输入项处理, 但gets() 函数接收输入的整个字符串直到回车ؓ止?br>getch()函数是从标准输入讑֤中读取一个字W,但这个字W不会在l端中显C出来?br>getchar()函数也是从标准输入设备中d一个字W,但这个字W在l端中显C出来?br>getline()函数是读取一行的字符丌Ӏ?br>


Kevin_Zhang 2010-11-22 21:11 发表评论
]]>
HDU1000http://m.shnenglu.com/zzfmars/archive/2010/08/21/124239.htmlKevin_ZhangKevin_ZhangSat, 21 Aug 2010 15:46:00 GMThttp://m.shnenglu.com/zzfmars/archive/2010/08/21/124239.htmlhttp://m.shnenglu.com/zzfmars/comments/124239.htmlhttp://m.shnenglu.com/zzfmars/archive/2010/08/21/124239.html#Feedback0http://m.shnenglu.com/zzfmars/comments/commentRss/124239.htmlhttp://m.shnenglu.com/zzfmars/services/trackbacks/124239.html#include "iostream"
#include
"stdio.h"
using namespace std;
int  main()
{
    
int a,b;
    
    
while( scanf("%d%d",&a,&b)==2)
    
{
     printf(
"%d\n",a+b);
    }

    
return 0;
}
http://acm.hdu.edu.cn/showproblem.php?pid=1000

Kevin_Zhang 2010-08-21 23:46 发表评论
]]>
C/C++ source code http://m.shnenglu.com/zzfmars/archive/2010/08/20/124061.htmlKevin_ZhangKevin_ZhangFri, 20 Aug 2010 01:38:00 GMThttp://m.shnenglu.com/zzfmars/archive/2010/08/20/124061.htmlhttp://m.shnenglu.com/zzfmars/comments/124061.htmlhttp://m.shnenglu.com/zzfmars/archive/2010/08/20/124061.html#Feedback0http://m.shnenglu.com/zzfmars/comments/commentRss/124061.htmlhttp://m.shnenglu.com/zzfmars/services/trackbacks/124061.htmlhttp://riddickbryant.javaeye.com/blog/583884

C/C++是最主要的编E语a。这里列Z50名优U|站和网|单,q些|站提供c/c++源代码。这份清单提供了源代码的链接以及它们的小说明。我已尽力包括最佳的C/C++源代码的|站。这不是一个完整的清单Q您有徏议可以联pLQ我欢q您的徏议,以进一步加斚w的清单?
1?a >http://snippets.dzone.com/tag/c/ --C千计的有用的C语言源代码片D?
2、http://www.hotscripts.com/category/c-cpp/scripts-programs/ Hotscripts --提供C百计的C和C++脚本和程序。所有程序都分ؓ不同的类别?
3?a >http://www.planetsourcecode.com/vb/default.asp?lngWId=3 --过万行C和C++免费的源代码
4?a >http://freshmeat.net/browse/164/ --过9000个C~写的项目?
5?a >http://www.daniweb.com/code/c.html --DANIWEB提供的实用代码段 ?
6?a >http://www.programmersheaven.com/tags/C/ --programmersheaven.com上的C~程资源?
7?a >http://www.ddj.com/code/ddj.html --Dr. Dobb’s Journal的源代码?
8?a >http://www.cprogramming.com/cgi-bin/source/source.cgi --C和C + +~程资源?
9?a >http://www.codecogs.com/ --CodeCogs是一协作的开放源码库QC/C++的数值方面的lg?
10?a >http://www.google.com/codesearch?q=programming++lang:c&cs_r=lang:c --h代码的C源代码?
11?a >http://www.codepedia.com/1/C --CodePedia是一个开攄关于pȝ~程和其他与电脑有关的议题?
12?a >http://www.cis.temple.edu/~ingargio/cis71/code/ --为学生提供的一个简单的C语言E序的列表?
13?a >http://www.codeproject.com/?cat=2 --codeproject提供的C/C++资源代码目?
14?a >http://www.thefreecountry.com/sourcecode/cpp.shtml --以下是一些C和C++库的DLLQVCLsQ源代码Q元Ӟ模块Q应用程序框ӞcdQ源代码片段{,你可以在您的目中用而不需要支付费用和版税?
15?a >http://people.sc.fsu.edu/~burkardt/cpp_src/cpp_src.html --q是一个全面的关于C++?45个源代码清单?
16?a >http://www.cplusplus.com/src/ --C++写的通用控制台程序和WindowsE序代码清单?
17?a >http://users.cs.fiu.edu/~weiss/dsaa_c++/code/ --C++语言数据l构与算法分析(W二版)的源代码?
18?a >http://c.snippets.org/ --C源代码片Dc?
19?a >http://www.bbdsoft.com/downloads.html --C++源代码?
20?a >http://www.moshier.net/ 天文学和数DY件源代码
21?a >http://cplus.about.com/od/cgames/C_Games_with_Source_Code.htm --游戏有关的C++源代码?
22?a >http://cliodhna.cop.uop.edu/~hetrick/c-sources.html --免费的C/C++数D源代码?
23?a >http://www.mathtools.net/C_C__/Utilities/index.html --C/C++工具?
24?a >http://www.programmerworld.net/resources/c_library.htm --免费C++源代码和其它有用的工兗?
25?a >http://www.cmcrossroads.com/bradapp/links/cplusplus-links.html --布拉德阿普尔的C++链接-资源Q项目,图书馆,教学和编码?
26?a >http://www.robertnz.net/cpp_site.html --q是一个收集了数C/C++|站链接列表的网c?
27?a >http://www.josuttis.com/libbook/examples.html --在这里,你可以看到ƈ下蝲所有的本书的C++标准库例??
28?a href="ftp://66.77.27.238/sourcecode/cuj/">ftp://66.77.27.238/sourcecode/cuj/ --C/C++用户杂志
29?a href="ftp://66.77.27.238/sourcecode/wd/">ftp://66.77.27.238/sourcecode/wd/ --Windows开发者网l?
30?a >http://www.einet.net/directory/65892/Developers.htm --CE序
31?a >http://www.daniweb.com/code/cplusplus.html --实用代码Dc?
32?a >http://snippets.dzone.com/tag/c --C++源代?
33?a >http://www.programmersheaven.com/tags/C --C++~程资源Qprogrammersheaven.com
34?a >http://www.google.com/codesearch?hl=en&lr=&q=programming --h代码搜烦-C++~程语言
35?a >http://www.codepedia.com/1/Cpp --CodePedia是一个开攄关于pȝ~程和其他与电脑有关的议题的|站?
36?a >http://www.codebeach.com/index.asp?TabID=1&CategoryID=3 --C++源代码,Codebeach提供
37?a >http://freshmeat.net/browse/165/ --5000目写的C++~程语言
38?a >http://cplus.about.com/od/codelibrary/Code_Library_for_C_C_and_C.htm --代码库C、C + +和CQ?
39?a >http://www.c.happycodings.com/ --Visual Basic、PHP、ASP技术、C、C++大全?
40?a >http://www.blueparrots.com/ --Borland C游戏Q图像和声音源代码范例?
41?a >http://www.java2s.com/Code/Cpp/CatalogCpp.htm --C++源代码?
42?a >http://www.yeohhs.com/modules/mydownloads/ --C与C++电子书和源代码示例?
43?a >http://www.brpreiss.com/books/opus4/programs/index.html C++的数学方E和公式源代码?
44?a >http://users.cs.fiu.edu/ C++?
45?a >http://www.josuttis.com/libbook/examples.html --C++标准?教程和参考资料?
46?a >http://emr.cs.uiuc.edu/~reingold/calendars.shtml Edward M. Reingold's Calendar Book, Papers, and Code?
47?a >http://cpp.snippets.org/ --c++源代码档案?
48?a >http://ubiety.uwaterloo.ca/~tveldhui/papers/techniques/ --用C和C++的解决科学问题?
49?a >http://c.ittoolbox.com/topics/core-c/ --C/C++的IT工具框?
50?a >http://www.le.ac.uk/cc/tutorials/c/ccccdbas.html --本文件中包含有大量的CCZE序?/p>



Kevin_Zhang 2010-08-20 09:38 发表评论
]]>
strcat-函数功能http://m.shnenglu.com/zzfmars/archive/2010/08/19/123907.htmlKevin_ZhangKevin_ZhangWed, 18 Aug 2010 17:19:00 GMThttp://m.shnenglu.com/zzfmars/archive/2010/08/19/123907.htmlhttp://m.shnenglu.com/zzfmars/comments/123907.htmlhttp://m.shnenglu.com/zzfmars/archive/2010/08/19/123907.html#Feedback0http://m.shnenglu.com/zzfmars/comments/commentRss/123907.htmlhttp://m.shnenglu.com/zzfmars/services/trackbacks/123907.html原型Qextern char *strcat(char *dest,char *src);
        
  用法Q?include <string.h>
  
  功能Q把src所?a class=innerlink title=字符 jQuery1282151723265="3">字符串添加到destl尾?覆盖destl尾处的'\0')q添?\0'?br>  
  说明Qsrc和dest所?a class=innerlink title=内存 target=_blank jQuery1282151723265="5">内存区域不可?a class=innerlink title=重叠 target=_blank jQuery1282151723265="6">重叠且dest必须有够的I间来容Usrc的字W串?br>        q回指向dest?a class=innerlink title=指针 target=_blank jQuery1282151723265="8">指针?br>http://www.hudong.com/wiki/strcat?hf=youdaocitiao&pf=youdaocitiao



Kevin_Zhang 2010-08-19 01:19 发表评论
]]>
INT_MAXhttp://m.shnenglu.com/zzfmars/archive/2010/08/14/123422.htmlKevin_ZhangKevin_ZhangSat, 14 Aug 2010 04:31:00 GMThttp://m.shnenglu.com/zzfmars/archive/2010/08/14/123422.htmlhttp://m.shnenglu.com/zzfmars/comments/123422.htmlhttp://m.shnenglu.com/zzfmars/archive/2010/08/14/123422.html#Feedback0http://m.shnenglu.com/zzfmars/comments/commentRss/123422.htmlhttp://m.shnenglu.com/zzfmars/services/trackbacks/123422.html#include"iostream"
#include
"math.h"
using namespace std;

int a;
long b;

int main()
{
    a
=INT_MAX;
    b
=pow(2.031)-1;
    cout
<<a<<endl;
    cout
<<b<<endl;
    
return 0;
}










---------------------------------------------------------------------

Kevin_Zhang 2010-08-14 12:31 发表评论
]]>
typedef 用法http://m.shnenglu.com/zzfmars/archive/2010/08/14/123408.htmlKevin_ZhangKevin_ZhangSat, 14 Aug 2010 01:55:00 GMThttp://m.shnenglu.com/zzfmars/archive/2010/08/14/123408.htmlhttp://m.shnenglu.com/zzfmars/comments/123408.htmlhttp://m.shnenglu.com/zzfmars/archive/2010/08/14/123408.html#Feedback0http://m.shnenglu.com/zzfmars/comments/commentRss/123408.htmlhttp://m.shnenglu.com/zzfmars/services/trackbacks/123408.htmlhttp://baike.baidu.com/view/1283800.htm
http://zhouwenjun.javaeye.com/blog/646392

W一、四个用?br>
用途一Q?br>
定义一U类型的别名Q而不只是单的宏替换。可以用作同时声明指针型的多个对象。比如:
char* pa, pb; // q多CW合我们的意图,它只声明了一个指向字W变量的指针Q?nbsp;
// 和一个字W变量;
以下则可行:
typedef 
char* PCHAR; // 一般用大写
PCHAR pa, pb; // 可行Q同时声明了两个指向字符变量的指?/span>
虽然Q?br>char *pa, *pb;
也可行,但相Ҏ说没有用typedef的Ş式直观,其在需要大量指针的地方Qtypedef的方式更省事?br>
用途二Q?br>
用在旧的C的代码中Q具体多旧没有查Q,帮助struct。以前的代码中,声明struct新对象时Q必要带上structQ即形式为: 
struct l构?nbsp;对象名,如:
struct tagPOINT1
{
int x;
int y;
}
;
struct tagPOINT1 p1; 

而在C
++中,则可以直接写Q结构名 对象名,卻I
tagPOINT1 p1;

估计某h觉得l常多写一个struct太麻烦了Q于是就发明了:
typedef 
struct tagPOINT
{
int x;
int y;
}
POINT;

POINT p1; 
// q样比原来的方式少写了一个structQ比较省事,其在大量用的时?/span>

或许Q在C
++中,typedef的这U用途二不是很大Q但是理解了它,Ҏ握以前的旧代码还是有帮助的,毕竟我们在项目中有可能会遇到较早些年代遗留下来的代码?br>
用途三Q?br>
用typedef来定义与q_无关的类型?br>比如定义一个叫 REAL 的Q点类型,在目标^C上,让它表示最高精度的cd为:
typedef 
long double REAL; 
在不支持 
long double 的^C上,改ؓQ?br>typedef double REAL; 
在连 
double 都不支持的^C上,改ؓQ?br>typedef float REAL; 
也就是说Q当跨^台时Q只要改?nbsp;typedef 本npQ不用对其他源码做Q何修攏V?br>标准库就q泛使用了这个技巧,比如size_t?br>另外Q因为typedef是定义了一U类型的新别名,不是单的字符串替换,所以它比宏来得E_Q虽然用宏有时也可以完成以上的用途)?br>
用途四Q?br>
为复杂的声明定义一个新的简单的别名。方法是Q在原来的声明里逐步用别名替换一部分复杂声明Q如此@环,把带变量名的部分留到最后替换,得到的就是原声明的最化版。D例:

1. 原声明:int *(*a[5])(intchar*);
变量名ؓaQ直接用一个新别名pFun替换a可以了Q?br>typedef 
int *(*pFun)(intchar*); 
原声明的最化版Q?br>pFun a[
5]; 

2. 原声明:void (*b[10]) (void (*)());
变量名ؓbQ先替换双部分括号里的QpFunParam为别名一Q?br>typedef 
void (*pFunParam)();
再替换左边的变量bQpFunx为别名二Q?br>typedef 
void (*pFunx)(pFunParam);
原声明的最化版Q?br>pFunx b[
10];

3. 原声明:doube(*)() (*e)[9]; 
变量名ؓeQ先替换左边部分QpFuny为别名一Q?br>typedef 
double(*pFuny)();
再替换右边的变量eQpFunParamy为别名二
typedef pFuny (
*pFunParamy)[9];
原声明的最化版Q?br>pFunParamy e; 

理解复杂声明可用?#8220;叛_法则”Q?br>从变量名看vQ先往叻I再往左,到一个圆括号p转阅ȝ方向Q括号内分析完就跛_括号Q还是按先右后左的顺序,如此循环Q直到整个声明分析完。D例:
int (*func)(int *p);
首先扑ֈ变量名funcQ外面有一对圆括号Q而且左边是一?/span>*Pq说明func是一个指针;然后跛_q个圆括P先看双Q又遇到圆括Pq说?*func)是一个函敎ͼ所以func是一个指向这cd数的指针Q即函数指针Q这cd数具有int*cd的Ş参,q回值类型是int?br>int (*func[5])(int *);
func双是一个[]q算W,说明func是具?个元素的数组Qfunc的左Ҏ一?/span>*Q说明func的元素是指针Q注意这里的*不是修饰funcQ而是修饰func[5]的,原因是[]q算W优先?/span>*高,func先跟[]l合Q。蟩个括P看右边,又遇到圆括号Q说明func数组的元素是函数cd的指针,它指向的函数hint*cd的Ş参,q回值类型ؓint?br>
也可以记?个模式:
type (
*)(.)函数指针 
type (
*)[]数组指针

W二、两大陷?br>
陷阱一Q?br>
CQtypedef是定义了一U类型的新别名,不同于宏Q它不是单的字符串替换。比如:
先定义:
typedef 
char* PSTR;
然后Q?br>
int mystrcmp(const PSTR, const PSTR);

const PSTR实际上相当于const char*吗?不是的,它实际上相当于char* const?br>原因在于constl予了整个指针本w以帔R性,也就是Ş成了帔R指针char* const?br>单来_C当const和typedef一起出现时Qtypedef不会是简单的字符串替换就行?br>
陷阱二:

typedef在语法上是一个存储类的关键字Q如auto?/span>extern、mutable?/span>static、register{一PQ虽然它q不真正影响对象的存储特性,如:
typedef 
static int INT2; //不可?/span>
~译失败,会提C?#8220;指定了一个以上的存储c?#8221;?br>
以上资料Qhttp:
//blog.sina.com.cn/s/blog_4826f7970100074k.html 作者:赤龙

W三、typedef ?nbsp;#define的区?br>
案例一Q?br>
通常Ԍtypedef要比#define要好Q特别是在有指针的场合。请看例子:

typedef 
char *pStr1;

#define pStr2 char *;

pStr1 s1, s2;

pStr2 s3, s4;

在上q的变量定义中,s1、s2、s3都被定义为char 
*Q而s4则定义成了charQ不是我们所预期的指针变量,Ҏ原因在?define只是单的字符串替换而typedef则是Z个类型v新名字?br>
案例二:

下面的代码中~译器会报一个错误,你知道是哪个语句错了吗?

typedef 
char * pStr;

char string[4= "abc";

const char *p1 = string;

const pStr p2 = string;

p1
++;

p2
++;

是p2
++出错了。这个问题再一ơ提醒我们:typedef?define不同Q它不是单的文本替换。上qC码中const pStr p2q不{于const char * p2?/span>const pStr p2和const long x本质上没有区别,都是对变量进行只读限Ӟ只不q此处变量p2的数据类型是我们自己定义的而不是系l固有类型而已。因此,const pStr p2的含义是Q限定数据类型ؓchar *的变量p2为只读,因此p2++错误?br>
W四部分资料Q?nbsp;typedef 抑制劣质代码

作者:Danny Kalev
~译QMTT 工作?br>
原文出处QUsing typedef to Curb Miscreant Code

摘要QTypedef 声明有助于创建^台无关类型,甚至能隐藏复杂和难以理解的语法。不怎样Q?nbsp;typedef 能ؓ代码带来意想不到的好处,通过本文你可以学习用 typedef 避免~欠Q从而代码更健壮?nbsp;

typedef 声明Q简U?nbsp;typedefQؓ现有cd创徏一个新的名字。比如h们常怋?nbsp;typedef 来编写更观和可ȝ代码。所谓美观,意指 typedef 能隐藏笨拙的语法构造以及^台相关的数据cdQ从而增强可UL性和以及未来的可l护性。本文下面将竭尽全力来揭C?nbsp;typedef 强大功能以及如何避免一些常见的陷阱?br>
QQ如何创建^台无关的数据cdQ隐藏笨拙且难以理解的语?/span>?

AQ?nbsp;使用 typedefs 为现有类型创建同义字?nbsp;

定义易于记忆的类型名
  typedef 使用最多的地方是创建易于记忆的cd名,用它来归档程序员的意图。类型出现在所声明的变量名字中Q位?nbsp;
''typedef'' 关键字右辏V例如:

typedef 
int size;此声明定义了一?nbsp;int 的同义字Q名字ؓ size。注?nbsp;typedef q不创徏新的cd。它仅仅为现有类型添加一个同义字。你可以在Q何需?nbsp;int 的上下文中?nbsp;sizeQ?br>
void measure(size * psz); size array[4];size len = file.getlength();std::vector <size> vs; typedef q可以掩饰符合类型,如指针和数组。例如,你不用象下面q样重复定义?nbsp;81 个字W元素的数组Q?br>
char line[81];char text[81];定义一?nbsp;typedefQ每当要用到相同cd和大的数组Ӟ可以q样Q?br>
typedef 
char Line[81]; Line text, secondline;getline(text);同样Q可以象下面q样隐藏指针语法Q?br>
typedef 
char * pstr;int mystrcmp(pstr, pstr);q里带我们到达W一?nbsp;typedef 陷阱。标准函?nbsp;strcmp()有两?#8216;const char *’cd的参数。因此,它可能会误导Z象下面这样声?nbsp;mystrcmp()Q?br>
int mystrcmp(const pstr, const pstr); q是错误的,按照序Q?#8216;const pstr’被解释ؓ‘char * const’Q一个指?nbsp;char 的常量指针)Q而不?#8216;const char *’Q指向常?nbsp;char 的指针)。这个问题很Ҏ解决Q?br>
typedef 
const char * cpstr; int mystrcmp(cpstr, cpstr); // 现在是正的CQ不什么时候,只要为指针声?nbsp;typedefQ那么都要在最l的 typedef 名称中加一?nbsp;constQ以使得该指针本w是帔RQ而不是对象?/span>

代码?br>  上面讨论?nbsp;typedef 行ؓ有点?nbsp;
#define 宏,用其实际cd替代同义字。不同点?nbsp;typedef 在编译时被解释,因此让编译器来应付超预处理器能力的文本替换。例如:

typedef 
int (*PF) (const char *const char *);q个声明引入?nbsp;PF cd作ؓ函数指针的同义字Q该函数有两?nbsp;const char * cd的参C及一?nbsp;int cd的返回倹{如果要使用下列形式的函数声明,那么上述q个 typedef 是不可或~的Q?br>
PF Register(PF pf);Register() 的参数是一?nbsp;PF cd的回调函敎ͼq回某个函数的地址Q其|名与先前注册的名字相同。做一ơ深呼吸。下面我展示一下如果不?nbsp;typedefQ我们是如何实现q个声明的:

int (*Register (int (*pf)(const char *const char *))) (const char *const char *); 很少有程序员理解它是什么意思,更不用说q种费解的代码所带来的出错风险了。显Ӟq里使用 typedef 不是一U特权,而是一U必需。持怀疑态度的h可能会问Q?#8220;OKQ有会写q样的代码吗Q?#8221;Q快速浏览一下揭C?nbsp;signal()函数的头文g <csinal>Q一个有同样接口的函数?br>
typedef 和存储类关键字(storage 
class specifierQ?br>  q种说法是不是有点o人惊Ӟtypedef 像 autoQ?/span>externQmutableQ?/span>staticQ和 register 一P是一个存储类关键字。这q是?nbsp;typedef 会真正媄响对象的存储Ҏ;它只是说在语句构成上Qtypedef 声明看v来象 staticQ?/span>extern {类型的变量声明。下面将带到W二个陷阱:

typedef register 
int FAST_COUNTER; // 错误~译通不q。问题出在你不能在声明中有多个存储类关键字。因为符?nbsp;typedef 已经占据了存储类关键字的位置Q在 typedef 声明中不能用 registerQ或M其它存储cd键字Q?/span>

促进跨^台开?br>  typedef 有另外一个重要的用途,那就是定义机器无关的cdQ例如,你可以定义一个叫 REAL 的Q点类型,在目标机器上它可以i获得最高的_ֺQ?br>
typedef 
long double REAL; 在不支持 long double 的机器上Q该 typedef 看v来会是下面这P

typedef 
double REAL; q且Q在q?nbsp;double 都不支持的机器上Q该 typedef 看v来会是这P ?br>
typedef 
float REAL; 你不用对源代码做M修改Q便可以在每一U^C~译q个使用 REAL cd的应用程序。唯一要改的是 typedef 本n。在大多数情况下Q甚臌个微的变动完全都可以通过奇妙的条件编译来自动实现。不是吗? 标准库广泛地使用 typedef 来创Lq_无关cdQsize_tQptrdiff ?nbsp;fpos_t 是其中的例子。此外,?nbsp;std::string ?nbsp;std::ofstream q样?nbsp;typedef q隐藏了镉K的,难以理解的模板特化语法,例如Qbasic_string<char, char_traits<char>Qallocator<char>> ?nbsp;basic_ofstream<char, char_traits<char>>?br>
作者简?br>  Danny Kalev 是一名通过认证的系l分析师Q专?nbsp;C
++ 和Ş式语a理论的Y件工E师?/span>1997 q到 2000 q期_他是 C++ 标准委员会成员。最q他以优异成l完成了他在普通语a学研I方面的士论文?nbsp;业余旉他喜Ƣ听古典音乐Q阅ȝ多利亚时期的文学作品Q研I?nbsp;Hittite、Basque ?nbsp;Irish Gaelic q样的自然语a。其它兴包括考古和地理。Danny 时常C?nbsp;C++ 论坛q定期ؓ不同?nbsp;C++ |站和杂志撰写文章。他q在教育机构讲授E序设计语言和应用语a评?br>


Kevin_Zhang 2010-08-14 09:55 发表评论
]]>
ɫ͵͵88888ŷƷþþ| þ99ֻоƷ| ƷƵþ| þñ˾þ| һaɫƬþ| þþƷר| þþþþþۺۺϺݺ| 99þɫĻ| Ʒþþ| þþþ| ѾþҹƷ| þþƷѿ| 69Ʒþþþþ޾Ʒ| ۿ ۺϾþþþùɫ ŷ һ| Ļav鲻þ| þúݺݸ߳޾Ʒ| ҹƷþþþþӰ777| þAVһ| ŷþþXXX| þþƷһ| ɫۺϾþþþۺ99| ձþ| ھƷ˾þþþAVӰԺ| 2021Ʒҹþ| þ¾ƷĻ| ݺɫۺþö| þѾƷav | һƷþ| ڸþþþþ| ޾Ʒþþþþ | þ˳ƷCAOPOREN | 18ƾþþAAAƬ| һþ㽶| þþþùһ| ˺ݺۺϾþ88| ޺ݺۺϾþ| bƷþþþþþ| þþûƬ| ҹþþþС˵| þƵ| ޾Ʒþǧն|