??xml version="1.0" encoding="utf-8" standalone="yes"?>午夜肉伦伦影院久久精品免费看国产一区二区三区 ,亚洲国产精品狼友中文久久久 ,色8久久人人97超碰香蕉987http://www.shnenglu.com/gujiayue/category/17719.htmlzh-cnMon, 30 May 2016 09:01:06 GMTMon, 30 May 2016 09:01:06 GMT60输入输出~冲区和的概念理解http://www.shnenglu.com/gujiayue/archive/2016/05/27/213595.html古月古月Fri, 27 May 2016 08:10:00 GMThttp://www.shnenglu.com/gujiayue/archive/2016/05/27/213595.htmlhttp://www.shnenglu.com/gujiayue/comments/213595.htmlhttp://www.shnenglu.com/gujiayue/archive/2016/05/27/213595.html#Feedback0http://www.shnenglu.com/gujiayue/comments/commentRss/213595.htmlhttp://www.shnenglu.com/gujiayue/services/trackbacks/213595.htmlQ本文章关于~冲区概늚理解大部分取自:(x)http://developer.51cto.com/art/201107/277186.htmQ?/span>

快递的寄送过E:(x)

源地址Q商家的仓库Q?#8212;—中{圎ͼ快递公司的仓库Q?#8212;—目的圎ͼ买家Q?/span>

我们从淘宝商家买衣服Q商安过快递公司把商品送到我们手里的这个过E可以Ş象的解释下缓存区和流的这个概c(din)?/span>

1Q?nbsp;淘宝商家不会(x)亲自把商品给买家送过来的Q因h率太低了(jin)Q商家会(x)通过快递公司这个中转,然后快递公司再把东襉K给买家。淘宝商家就是在键盘?sh)打字,买家是E序Q程序需要读取从键盘?sh)的输入的字Q缓冲区是快递公司的仓库?/span>

2Q?nbsp;商品的几U位|状态:(x)商家仓库Q快递仓库,买家手中Q还有一U状态就是在路上。输入输出的就是指的在路上?/span>

3Q?nbsp;快递收货员收到商品放到自q中{仓库中。但是快递公司肯定等仓库中的商品U篏C定程度才开始派送。行~冲是遇到换行W时p为需要执?/span>I/O操作?jin)?br />


      一Q缓冲区的概?/span>

~冲区又可以UCؓ(f)~存。计机中的内存可以被认为是盘的缓存。当cpud文g、执行程序时Q不?x)直接从盘(sh)读取,而是先把文g~存到内存(sh)Q然后再从内存(sh)d?/span>

对于C++E序来说Q当cMcinQ?/span>getcharq样的对象或者函数读取输入时Q不?x)直接直接读键盘(sh)的输入Q而是q样的一个过E:(x)cin——输入~冲?#8212;—键盘。我们从键盘?sh)输入的字符先存到缓冲区里面Q?/span>cin从缓冲区里面d输入。对于输出来_(d)E序的结果不?x)直接显C到屏幕上,而是先存攑ֈ~冲区,然后cout把内容从~冲出到屏幕?/span>cin?/span>cout本质上都是对~冲Z的内容进行操作?/span>

如果没有~冲区就?x)大大降?/span>CPU的效率,因ؓ(f)cpu不得不一直等待用L(fng)输入Q而不能执行其他的操作Qh打字输入的速度再快Q也比不?/span>CPU的执行速度Qh在输入两个字W之间的间隔旉Q?/span>cpu完全可以d别的事情?/span>

~冲区分ZU全~冲、行~冲和不带缓册Ӏ?/span>

1、全~冲

在这U情况下Q当填满标准I/O~存后才q行实际I/O操作。全~冲的典型代表是对磁盘文件的d?/span>

2、行~冲

在这U情况下Q当在输入和输出中遇到换行符Ӟ执行真正?/span>I/O操作。这Ӟ我们输入的字W先存放在缓冲区Q等按下回R键换行时才进行实际的I/O操作。典型代表是键盘输入数据?/span>

3、不带缓?/span>

也就是不q行~冲Q标准出错情?/span>stderr是典型代表,q得出错信息可以直接尽快地昄出来?/span>

~冲区的h指的是缓冲区的内容被清空hQ这也就意味着h之前pȝ?x)对~冲区内容进?/span>I/Od。下?/span>4U情况会(x)触发~冲区的hQ?/span>

~冲区满Ӟ

执行flush语句Q?/span>

执行endl语句Q?/span>

关闭文g?/span>

C/C++E序里面的缓冲区指的是ؓ(f)标准输入与标准输?gu)|的~冲区,如果我们不认为的讄的话Q系l会(x)自动的ؓ(f)标准输入与标准输入设|一个缓冲区Q这个缓冲区的大通常?/span>4Kb的大?/span>

ANSI C要求下列~存特征Q?/span>

(1) 当且仅当标准输入和标准输出ƈ不涉?qing)交互作用设备(键盘Q屏q)(j)Ӟ它们才是全缓存的?/span> d文g的时候就是全~存?/span>

(2)标准出错决不?x)是全缓存的?/span>

(3)标准输入和输出涉?qing)交互作用设备时Q虽然没有明规定是不带~存的还是行~存的,但一般系l默认它们是行缓存的?/span>

 因此我们l常要用的标准输入和输出Q?/span>stdin?/span>stdout?/span>stderr的缓存特征是Q?/span>stdin?/span>stdout是行~存Q?/span>stderr是无~存的?/span>cin?/span>cout都是从缓冲区d

 

 

 

二、流的概?/span>

是一个过E,一个动态的概念。可以把想象成水在水管中流动的q程Q想象成商品快递运送的q程?/span>Cin?/span>cout是执行这个过E的人?/span>

对于输入Q?/span>cin负责把输入缓冲区中的内容传递给E序Q?/span>

对于输出Q?/span>cout负责把输出缓冲区中的内容传递给屏幕?/span>

Cin?/span>cout把缓冲区的数据变成流Q然后搬q到相应的目的地?/span>Cin?/span>cout是个搬q工Q搬q的q程是?/span>


      三、代码案?br />      W一D代码:(x)

int main()
{
    string str;
    int i=0;
    while (cin >> str)
    {
        cout << str<<endl;
        cout << ++i << endl;
    }
    return 0;
}
E序执行q程中输入:(x)i love you
最l结果是Q?br />
i
1
love
2
you
3

执行q程中,E序q不?x)在每次输入一个空格时打Cơ,而在在完全输入一行字W串q摁下回车后Q才?x)打印。原因就是在我们输入回R之前的一行字W串都只是存攑ֈ?jin)?f)标准输入分配的缓冲区中,q是一个行~冲区,在遇到换行符之前Q缓冲区不会(x)h也就不会(x)触发I/O操作Qcin也就没有在读取数据。输入回车后Qcin开始执行I/O操作Q读取缓冲区中的字符Q首先读取iQ然后遇C(jin)I格Q此ơ读取完成,执行循环。然后接着dloveQ又遇到?jin)空|d完成Q执行@环。最后读取了(jin)you?br />W二D代码:(x)

int main()
{
    char c;
    //W一ơ调用getchar()函数  
    
//E序执行Ӟ(zhn)可以输入一串字Wƈ按下回R键,按下回R键后该函数才q回  
    c = getchar();
    //昄getchar()函数的返回?nbsp; 
    cout << c << endl;
    //暂停  
    system("PAUSE");
    //循环多次调用getchar()函数  
    
//每ơ调用getchar()函数的返回值显C出?nbsp; 
    
//直到遇到回RW才l束  
    while ((c = getchar()) != '\n')
    {
        printf("%c", c);
    }
    //暂停  
    system("PAUSE");
    return 0;
}
执行E序Q输入:(x)abcdefg,然后回R
E序l果如下Q?br />a
bcdefg

W一ơ执行到getcharӞ׃此时~冲区里面没有Q何内容,所以程序等待键盘的输入Q输入abcdefg后,然后输入回RQ触发了(jin)行缓冲的条gQ执行I/OQgetchar开始读取缓冲区的内容,׃此函数只d一个字W,所以读完字Wa后,dl束Q执行下面的语句Q将a打印到屏q。由于缓冲区中字W只被读取了(jin)1个字WaQ剩余的bcdefgq在~冲ZQ因此执行到while中的getcharӞ直接d~冲Z的内容,也就是依ơ读取bcdefgQ回车符也是~冲Z的一个字W,当读取完回R后,while循环l束?br />



古月 2016-05-27 16:10 发表评论
]]>
c++中explict关键字的说明和?/title><link>http://www.shnenglu.com/gujiayue/archive/2012/09/19/191270.html</link><dc:creator>古月</dc:creator><author>古月</author><pubDate>Wed, 19 Sep 2012 10:15:00 GMT</pubDate><guid>http://www.shnenglu.com/gujiayue/archive/2012/09/19/191270.html</guid><wfw:comment>http://www.shnenglu.com/gujiayue/comments/191270.html</wfw:comment><comments>http://www.shnenglu.com/gujiayue/archive/2012/09/19/191270.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/gujiayue/comments/commentRss/191270.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/gujiayue/services/trackbacks/191270.html</trackback:ping><description><![CDATA[<span style="font-size: 13px; color: #008080; ">先看下面q一个简单的代码?br /><br /></span><span style="font-size: 13px; color: #008080; "> 1</span><span style="font-size: 13px; background-color: #eeeeee; "> #include <iostream></span><br style="font-size: 13px; " /><span style="font-size: 13px; color: #008080; "> 2</span><span style="font-size: 13px; background-color: #eeeeee; "> </span><span style="font-size: 13px; color: #0000ff; ">using</span><span style="font-size: 13px; background-color: #eeeeee; "> </span><span style="font-size: 13px; color: #0000ff; ">namespace</span><span style="font-size: 13px; background-color: #eeeeee; "> std;</span><br style="font-size: 13px; " /><span style="font-size: 13px; color: #008080; "> 3</span><span style="font-size: 13px; background-color: #eeeeee; "> </span><span style="font-size: 13px; color: #0000ff; ">class</span><span style="font-size: 13px; background-color: #eeeeee; "> my</span><br style="font-size: 13px; " /><span style="font-size: 13px; color: #008080; "> 4</span><span style="font-size: 13px; background-color: #eeeeee; "> {</span><br style="font-size: 13px; " /><span style="font-size: 13px; color: #008080; "> 5</span><span style="font-size: 13px; background-color: #eeeeee; "> </span><span style="font-size: 13px; color: #0000ff; ">private</span><span style="font-size: 13px; background-color: #eeeeee; ">:</span><br style="font-size: 13px; " /><span style="font-size: 13px; color: #008080; "> 6</span><span style="font-size: 13px; background-color: #eeeeee; ">     </span><span style="font-size: 13px; color: #0000ff; ">int</span><span style="font-size: 13px; background-color: #eeeeee; "> t;</span><br style="font-size: 13px; " /><span style="font-size: 13px; color: #008080; "> 7</span><span style="font-size: 13px; background-color: #eeeeee; "> </span><span style="font-size: 13px; color: #0000ff; ">public</span><span style="font-size: 13px; background-color: #eeeeee; ">:</span><br style="font-size: 13px; " /><span style="font-size: 13px; color: #008080; "> 8</span><span style="font-size: 13px; background-color: #eeeeee; ">     my(){};</span><br style="font-size: 13px; " /><span style="font-size: 13px; color: #008080; "> 9</span><span style="font-size: 13px; background-color: #eeeeee; ">     my(</span><span style="font-size: 13px; color: #0000ff; ">int</span><span style="font-size: 13px; background-color: #eeeeee; "> i):t(i){};</span><br style="font-size: 13px; " /><span style="font-size: 13px; color: #008080; ">10</span><span style="font-size: 13px; background-color: #eeeeee; ">     </span><span style="font-size: 13px; color: #0000ff; ">int</span><span style="font-size: 13px; background-color: #eeeeee; "> </span><span style="font-size: 13px; color: #0000ff; ">get</span><span style="font-size: 13px; background-color: #eeeeee; ">()</span><br style="font-size: 13px; " /><span style="font-size: 13px; color: #008080; ">11</span><span style="font-size: 13px; background-color: #eeeeee; ">     {</span><br style="font-size: 13px; " /><span style="font-size: 13px; color: #008080; ">12</span><span style="font-size: 13px; background-color: #eeeeee; ">         </span><span style="font-size: 13px; color: #0000ff; ">return</span><span style="font-size: 13px; background-color: #eeeeee; "> t;</span><br style="font-size: 13px; " /><span style="font-size: 13px; color: #008080; ">13</span><span style="font-size: 13px; background-color: #eeeeee; ">     }</span><br style="font-size: 13px; " /><span style="font-size: 13px; color: #008080; ">14</span><span style="font-size: 13px; background-color: #eeeeee; ">     </span><span style="font-size: 13px; color: #0000ff; ">void</span><span style="font-size: 13px; background-color: #eeeeee; "> print(my d)</span><br style="font-size: 13px; " /><span style="font-size: 13px; color: #008080; ">15</span><span style="font-size: 13px; background-color: #eeeeee; ">     {</span><br style="font-size: 13px; " /><span style="font-size: 13px; color: #008080; ">16</span><span style="font-size: 13px; background-color: #eeeeee; ">         cout<<d.</span><span style="font-size: 13px; color: #0000ff; ">get</span><span style="font-size: 13px; background-color: #eeeeee; ">()<<endl;</span><br style="font-size: 13px; " /><span style="font-size: 13px; color: #008080; ">17</span><span style="font-size: 13px; background-color: #eeeeee; ">     }</span><br style="font-size: 13px; " /><span style="font-size: 13px; color: #008080; ">18</span><span style="font-size: 13px; background-color: #eeeeee; "> };</span><br style="font-size: 13px; " /><span style="font-size: 13px; color: #008080; ">19</span><span style="font-size: 13px; background-color: #eeeeee; "> </span><br style="font-size: 13px; " /><span style="font-size: 13px; color: #008080; ">20</span><span style="font-size: 13px; background-color: #eeeeee; "> </span><span style="font-size: 13px; color: #0000ff; ">int</span><span style="font-size: 13px; background-color: #eeeeee; "> main()</span><br style="font-size: 13px; " /><span style="font-size: 13px; color: #008080; ">21</span><span style="font-size: 13px; background-color: #eeeeee; "> {</span><br style="font-size: 13px; " /><span style="font-size: 13px; color: #008080; ">22</span><span style="font-size: 13px; background-color: #eeeeee; ">     my t;</span><br style="font-size: 13px; " /><span style="font-size: 13px; color: #008080; ">23</span><span style="font-size: 13px; background-color: #eeeeee; ">     </span><span style="font-size: 13px; color: #0000ff; ">int</span><span style="font-size: 13px; background-color: #eeeeee; "> i=3;</span><br style="font-size: 13px; " /><span style="font-size: 13px; color: #008080; ">24</span><span style="font-size: 13px; background-color: #eeeeee; ">     t.print(i);</span><br style="font-size: 13px; " /><span style="font-size: 13px; color: #008080; ">25</span><span style="font-size: 13px; background-color: #eeeeee; ">     </span><span style="font-size: 13px; color: #0000ff; ">return</span><span style="font-size: 13px; background-color: #eeeeee; "> 0;</span><br style="font-size: 13px; " /><span style="font-size: 13px; color: #008080; ">26</span><span style="font-size: 13px; background-color: #eeeeee; "> }</span><br style="font-size: 13px; " /><span style="font-size: 13px; color: #008080; "><br /></span><span style="font-size: 14pt; ">main函数中t.print(i);的调用,myc里面print函数接受的数据类型的myQ不是intQ但q段E序仍然能够正常q行Q是因ؓ(f)myc里面存在一个只有一个Ş参的构造函数?br /></span><br style="font-size: 13px; " /><span style="font-size: 14pt; ">当在一个需要mycd对象的地方(比如print函数Q就需要一个mycd对象Q,但是如果却没有给一个mycd对象Q给?jin)一个其他类型的对象Q比如intQ那么这个时候就?x)看q个cL没有定义一个只接受一个参数的构造函敎ͼ而且q个形参必须是intQ然后构造出一个mycd临时对象Q再把这个(f)时对象给需要mycd象的地方Q完成一U隐式的转换?/span><br style="font-size: 13px; " /><span style="font-size: 14pt; ">注意Q如果这个类有一个接受一个参数的构造函敎ͼ但是q个参数的类型比如是stringQ这个隐式{换肯定就不会(x)发生?jin),~译时会(x)提示错误?br /></span><br style="font-size: 13px; " /><span style="font-size: 14pt; ">MQ隐式{换会(x)发生在,本来需要一个这U类对象的时候,却给?jin)一个其他的数据cdQ而且cM恰好有一个只接受一个这U数据类型参数的构造函敎ͼ׃(x)先调用这个构造函数生成一个(f)时对象,接着这临时对象用于需要这U类对象的地斏V?/span><br style="font-size: 13px; " /><br style="font-size: 13px; " /><span style="font-size: 14pt; ">但是很多时候,q种隐式转换?x)带来很大的ȝ?ch)Q因此如果自己定义的cMQ有一个只接受一个参数的构造函敎ͼ</span><span style="font-family: verdana, 'ms song', ?hu)? Arial, 微Y雅黑, Helvetica, sans-serif; line-height: 19px; background-color: #fefef2; font-size: 14pt; ">除非有一个好理由允许构造函数被用于隐式cd转换Q否?/span><span style="font-size: 14pt; ">那么p在这个构造函数前面加一个关键词 explicitQ表明不?x)发生隐式{换?/span><img src ="http://www.shnenglu.com/gujiayue/aggbug/191270.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/gujiayue/" target="_blank">古月</a> 2012-09-19 18:15 <a href="http://www.shnenglu.com/gujiayue/archive/2012/09/19/191270.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>再谈下声明、定义、初始化、赋值和externhttp://www.shnenglu.com/gujiayue/archive/2012/06/07/177916.html古月古月Thu, 07 Jun 2012 07:41:00 GMThttp://www.shnenglu.com/gujiayue/archive/2012/06/07/177916.htmlhttp://www.shnenglu.com/gujiayue/comments/177916.htmlhttp://www.shnenglu.com/gujiayue/archive/2012/06/07/177916.html#Feedback0http://www.shnenglu.com/gujiayue/comments/commentRss/177916.htmlhttp://www.shnenglu.com/gujiayue/services/trackbacks/177916.html

1.      声明、定义、初始化和赋值四个术语有着本质的不同,虽然有时候看h差不多甚臛_全一P但如果不搞清楚很Ҏ(gu)出现错误Q或者错?jin)不知道怎么攏V?/span>

 

2.     a: extern关键词用来表明这是一个声明:(x)extern int I;变量i是一个声明?/span>声明前面一定要有一个关键字externQ没有这个关键词׃是一个声明?/span>

b: 没有extern是一个定义,比如int i=9Q是一个定义,特别要注意的?/span>int i;q也是一个定义?/span>

c: 初始化就是在变量定义时给变量一个初|所以初始化语句也一定是一个定义语句,但反q来׃对了(jin)Q因为类gQ?/span>int iQ就是定义,但没有初始化。特别要注意的是Q?/span>extern int i = 9Q虽然有extern关键词,但是因ؓ(f)初始化了(jin)Q所以这也是一个定?/span>Q不是声明?/span>

d: 赋D句就单了(jin)Q赋D句是l一个已l定义的变量Q不这个变量有没有初始化)(j)一个新倹{特别要注意的是Q?/span>要给赋值的变量必须已经定义q了(jin)Q仅仅声明是不行的?/span>

 

3.       extern关键词除?jin)表明这是一个声明以外,更重要的是表明:(x)所声明的变量的定义可能是在E序中其他文仉。如下代?br />

    //file1.cpp

#include <iostream>
using namespace std;
extern int i;//q是一个声明,告诉~译器变量i的定义有可能是在其他源文件中Q即使本文g中没有i的定义,你也不要报错?/span>
void main()
{
    extern int i;//同样是对i的声明,作用与上面的声明完全一P说明声明可以存在多个Q实际上q两个声明只要Q意一个就可以?jin)。但是两个声明语句如果一个都没有Q编译器׃(x)认ؓ(f)变量i没有定义Q会(x)报错?br />
    i=0;//赋D句,l变量i一个新|变量赋值前必须要已l定义了(jin)Q如果不存在file2文g中的定义语句Q虽然不?x)出现编译错误,但是链接会(x)有错?/span>
    cout<<i;
}

//file2.cpp

int i;//首先是一个定义,而且是一个没有初始化的定义(不过实际上全局变量i被默认初始化?Q,变量i被定义在file2源文件中

 

 

4.      一个程序中可能包括不只一个文Ӟ所有文件中同一个变量(其实主要说的全局变量Q必Ld只能定义一ơ,但是声明可以有无C。而且如果文gA中用到的变量的定义是在其他文件中Q那么在文gA中用q个变量之前Q一定要加上一?/span>extern声明语句Q告诉编译器我所用的q个变量有可能是在其他文仉

5.   extern int i=9Q上面已l提到虽然有externQ但q也是一个定义,因ؓ(f)初始化了(jin)?span style="color: red; ">cM于这U有extern也有初始化的语句Q只能出现在全局作用域,如果出现在函数内部,q是错误的?/span>

6.       Q{Q有关编译器的一个特点:(x)C~译器一般都属于按文件编译,是说编译时多个源文件自q译自qQ互不媄(jing)响,好像只有自己一个文件?/span>只要每个文g~译时没有出现错误,那么׃?x)发生编译时错误。但?/span>没有发生~译错误Qƈ不代表程序就没有错误Q因?sh)(x)发生链接错?/span>。比如下面这两个代码

     //A.cpp
int i;//q是变量i的定?/span>
 
void main()
{
}

//B.cpp
int i;//q也是变量i的定?/span>
~译时两个文件A和B是相互不影响的,所以编译时不会(x)出现M错误Q但是这个程序是有问题的Q因为全局变量i是被定义?jin)两ơ的Q所以链接时׃(x)报告cM于下面的错误Q?br />

B.obj : error LNK2005: "int i" (?i@@3HA) already defined in A.obj

Debug/A.exe : fatal error LNK1169: one or more multiply defined symbols found

另外上面也提C(jin)Q编译时各个文g是相互不影响的,~译器是不会(x)认ؓ(f)在这个文件中没有定义的变量其实很有可能h家是个全局变量Q在其他文g中定义了(jin)Q这p报错。解x(chng)法就是用extern声明一个变量,告诉~译器h家这个变量不是没有定义,只是在其他文件中定义?/span>Q你别报错了(jin)?/span>

 



古月 2012-06-07 15:41 发表评论
]]>
新学到的有关cin输入的特点、用?/title><link>http://www.shnenglu.com/gujiayue/archive/2012/05/28/cin.html</link><dc:creator>古月</dc:creator><author>古月</author><pubDate>Sun, 27 May 2012 16:20:00 GMT</pubDate><guid>http://www.shnenglu.com/gujiayue/archive/2012/05/28/cin.html</guid><wfw:comment>http://www.shnenglu.com/gujiayue/comments/176424.html</wfw:comment><comments>http://www.shnenglu.com/gujiayue/archive/2012/05/28/cin.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/gujiayue/comments/commentRss/176424.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/gujiayue/services/trackbacks/176424.html</trackback:ping><description><![CDATA[<div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->#include <iostream><br /><br /><span style="color: #0000FF; ">using</span> <span style="color: #0000FF; ">namespace</span> std;<br /><span style="color: #0000FF; ">void</span> main()<br />{<br />    <span style="color: #0000FF; ">double</span> val;<br />    <span style="color: #0000FF; ">char</span> ch0,ch1;<br />    cin>>val;<br />    cout<<val<<endl;<br />    cin>>ch0;<br />    cout<<ch0<<endl;<br />    cin>>ch1;<br />    cout<<ch1<<endl;<br />}<br /><br />cin输入用法之前学的不认真Q忽略到?jin)?br />q段代码很简单,开始第一个输入的时候,比如直接输入Q?23ab。最后的l果是把123l了(jin)valQal了(jin)ch0,bl了(jin)ch1?br />也就是说Q当cinl一个doubleӞq时如果你的输入?23abQ不是单U的一个数字时Q那么将只是把输入的数字部分123ldoubleQ?span style="color: red; "><strong>但是剩下的ab不是单的遗弃?/strong></span>Q而是l箋(hu)留在输入中Q等待下一ơ出现cin再把abl到下一个要从输入流得到值的变量?/div><img src ="http://www.shnenglu.com/gujiayue/aggbug/176424.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/gujiayue/" target="_blank">古月</a> 2012-05-28 00:20 <a href="http://www.shnenglu.com/gujiayue/archive/2012/05/28/cin.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>鄙hq辈子编写的W一个游戏程序:(x)猜拳Q?好激动,׃n下c++源代?/title><link>http://www.shnenglu.com/gujiayue/archive/2012/01/13/164145.html</link><dc:creator>古月</dc:creator><author>古月</author><pubDate>Fri, 13 Jan 2012 14:30:00 GMT</pubDate><guid>http://www.shnenglu.com/gujiayue/archive/2012/01/13/164145.html</guid><wfw:comment>http://www.shnenglu.com/gujiayue/comments/164145.html</wfw:comment><comments>http://www.shnenglu.com/gujiayue/archive/2012/01/13/164145.html#Feedback</comments><slash:comments>7</slash:comments><wfw:commentRss>http://www.shnenglu.com/gujiayue/comments/commentRss/164145.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/gujiayue/services/trackbacks/164145.html</trackback:ping><description><![CDATA[     摘要: 矛_剪子布的猜拳游戏Q在VC下编译运行下Q生成的.EXE文gQ就可以单独拿出来玩游戏?jin)。这个游戏属?.1版本Q最原始?.0版本主要部分和这个差不多Q?.1主要是在原来的基上与玩家的交互做?jin)一些更加友好的改进Q感谢提出改q意见的宿舍兄弟Q程序基本没有太大的技术含量,自认为程序核?j)的部??sh)脑随机l出的猜拟뀂本人想C(jin)一个很单但自认为挺巧妙的方法(小的骄(jing)傲下Q,不多说了(jin)看代码吧Q如果代码有什...  <a href='http://www.shnenglu.com/gujiayue/archive/2012/01/13/164145.html'>阅读全文</a><img src ="http://www.shnenglu.com/gujiayue/aggbug/164145.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/gujiayue/" target="_blank">古月</a> 2012-01-13 22:30 <a href="http://www.shnenglu.com/gujiayue/archive/2012/01/13/164145.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>字符串操作函C的参数问?/title><link>http://www.shnenglu.com/gujiayue/archive/2011/12/25/162780.html</link><dc:creator>古月</dc:creator><author>古月</author><pubDate>Sun, 25 Dec 2011 08:25:00 GMT</pubDate><guid>http://www.shnenglu.com/gujiayue/archive/2011/12/25/162780.html</guid><wfw:comment>http://www.shnenglu.com/gujiayue/comments/162780.html</wfw:comment><comments>http://www.shnenglu.com/gujiayue/archive/2011/12/25/162780.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/gujiayue/comments/commentRss/162780.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/gujiayue/services/trackbacks/162780.html</trackback:ping><description><![CDATA[<div>q个首先先解释下一个很基础但是却很重要又常常容易搞L(fng)问题?br />char a[]和char*的区别?br />《c语言E序设计》(中文版)(j)的解释挺不错的,我再大概说一下?br />..............................<br />char ame[] = "nw is the time"; <br />char *pme = "now is the time";<br />首先说pme是把一个指向该字符数组的指针赋值给pme.q个q程没有涉及(qing)到字W串的复Ӟ只是有指针的操作。pme首先是一个指针,q个指针指向一个字W串帔RQ这个指针此后可以被修改为指向其它字W串Q但是如果修改字W串本n的内容,l果是未定义的。ame是一个存攑ֈ始化字符串和I字W的一l数l,数组中的单个字符都是可以被修改的Q但是ame是个地址帔RQ是不可以被修改的,它始l指向这一个字W串?br /><br />string.h中定义了(jin)很多字符串操作函敎ͼ比如strncatQ这些函数至都有两个参敎ͼW一个参数是目的字符ԌW二个参数是源字W串?br />关于q个参数的类型到底用哪种Q?strong style="color: #ff0000; font-size: 14pt">要看相关的参数内容在函数执行完以后是不是?x)发生改变。如果参数内容发生改变(sh)(jin)p用char[]Q如果参数的内容不发生改变则两个都可以用?/strong><strong><br /><br /></strong>比如strncatQs,ct,n)Q函数的作用是把ct的前n个字W连接到s的后面,最后补上一个空字符。那么显然执行完以后s的内Ҏ(gu)变化?jin)的Q所以定义s是必Lchar s[80]Q不能是char *sQ对于ct来说内容没有发生变化Q怎么定义都可以?jin)?/div><img src ="http://www.shnenglu.com/gujiayue/aggbug/162780.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/gujiayue/" target="_blank">古月</a> 2011-12-25 16:25 <a href="http://www.shnenglu.com/gujiayue/archive/2011/12/25/162780.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>fopen函数的用的几种方式http://www.shnenglu.com/gujiayue/archive/2011/12/25/162775.html古月古月Sun, 25 Dec 2011 06:08:00 GMThttp://www.shnenglu.com/gujiayue/archive/2011/12/25/162775.htmlhttp://www.shnenglu.com/gujiayue/comments/162775.htmlhttp://www.shnenglu.com/gujiayue/archive/2011/12/25/162775.html#Feedback0http://www.shnenglu.com/gujiayue/comments/commentRss/162775.htmlhttp://www.shnenglu.com/gujiayue/services/trackbacks/162775.html#include<stdio.h>
#include
<string.h>
 
int main()
{
    FILE 
* handle;
    
char con[100];
    
//W一U用fopen的方式,windowspȝ是直接输入文件的l对路径需要这U方?e:\\aaa.txt",注意是两个反斜杠Q一个反斜杠的话错?br />    //handle=fopen("e:\aaa.txt","r");

    
//W二U用fopen的方式,利用一个字W串来保存文件\径和名字Q运行程序后Q在dos下提CZ输入路径名字Q可以输?e:\\aaa.txt"Q?br />    //或?e:\aaa.txt"Q也是说dos下一个反斜杠或者两个反斜杠都是正确?br />    //char buf[80];
    
//printf("please input the filename you want to open:");
    
//gets(buf);
    
//handle=fopen(buf,"r");

    
//利用一个初始化好的字符串也可以正确的用fopenQ以下这几种初始化方式都是正的都是两个反斜?br />    //char buf[]="e:\\aaa.txt";const char buf[100]="e:\\aaa.txt";
    char *buf="e:\\aaa.txt";
    handle
=fopen(buf,"r");

    
if(!handle)
        perror(
"can not open this file\n");
    
else
        printf(
"you have opened this file successfully!\n");
    fgets(con,
100,handle);
    printf(
"the content of file is:%s\n",con);
    fclose(handle);
    
return 0;
}

主要介绍?jin)fopen函数的第一个参数的使用Q代码里面说的已l很清楚?jin),其余cMfopen的函数的使用也一?img src ="http://www.shnenglu.com/gujiayue/aggbug/162775.html" width = "1" height = "1" />

古月 2011-12-25 14:08 发表评论
]]>
linux环境下调试有x(chng)?qing)到条g~译的cE序的小用法http://www.shnenglu.com/gujiayue/archive/2011/09/14/155793.html古月古月Wed, 14 Sep 2011 15:56:00 GMThttp://www.shnenglu.com/gujiayue/archive/2011/09/14/155793.htmlhttp://www.shnenglu.com/gujiayue/comments/155793.htmlhttp://www.shnenglu.com/gujiayue/archive/2011/09/14/155793.html#Feedback0http://www.shnenglu.com/gujiayue/comments/commentRss/155793.htmlhttp://www.shnenglu.com/gujiayue/services/trackbacks/155793.html1 #if 表达?br />       E序D?
  #else
       E序D?
 #endif
   很简单,表达式ؓ(f)真编?Q否则编??br />
2 #ifdef 标识W?br />      E序D?
   #else
      E序D?
   #endif
如果标识W已?define定义q,则ؓ(f)真编?Q否则编?

3 ?的基本一致就是把ifdef换成ifndef。用法是为假~译1Q否?

比如#include <stdio.h>
int main()
{
#ifdef _DEBUG
printf("hello world\n");
#else
printf("no debug");
#endif
return 0;
}

在linux用gcc~译是,如果使用gcc -D_DEBUG -o main main.c。则是说明定义q_DEBUGQ运行结果是hello world。注意是-D选项Q?D后面紧跟着标识W名?br />如果使用Qgcc -o main mian.cQ怎说明没有定义标识符Q运行结果是no debug?jin)?br />
当然Q也可以直接再代码里昄写上一句:(x)#define _DEBUG,也能有相同效果?br />


古月 2011-09-14 23:56 发表评论
]]>
宏定义的用法详解http://www.shnenglu.com/gujiayue/archive/2011/09/14/155791.html古月古月Wed, 14 Sep 2011 15:42:00 GMThttp://www.shnenglu.com/gujiayue/archive/2011/09/14/155791.htmlhttp://www.shnenglu.com/gujiayue/comments/155791.htmlhttp://www.shnenglu.com/gujiayue/archive/2011/09/14/155791.html#Feedback0http://www.shnenglu.com/gujiayue/comments/commentRss/155791.htmlhttp://www.shnenglu.com/gujiayue/services/trackbacks/155791.html
1、不带参数的宏定?br />
  q是最单的?jin),比?define PI 3.1415926
预编译的时候,把代码中的PI替换p?jin)。一般情况下宏名用大写字母,不要在行末加分号?br />
2、带参数的宏定义

不只是进行宏体的替换Q还要进行参数的替换?br />比如Q?define MAX(xQyQ?Qx>y)?x:y
宏展开的时候要语句中宏名后面的括号内的实参代替Ş参。另外ؓ(f)?jin)避免发生错误,凡是带运符的参数要用圆括号括v来?br />
3、不常见但是很重要的用法
(1)#define FUN(a) "a"
那么当输入FUN(345)是,照样?x)被替换?#8220;a”Q无论宏的实参是什么,都不?x)?jing)响其被替换成"a"的命q?
  也就是说Q?"内的字符不被当成形参Q即使它和一模一栗?br />(2)有参宏定义中#的用?
 #define STR(str) #str
  str前面的那?用于把宏定义中的参数两端加上字符串的""
 比如代码中有STR(my#name),那么在展开的时候被替换?my#name"?br />一般由L字符都可以做形参Q但以下情况?x)出错?x)
  STR())q样Q编译器不会(x)?#8220;)”当成STR()的参数?
  STR(,)同上Q编译器不会(x)?#8220;,”当成STR的参数?
  STR(A,B)如果实参q多Q则~译器会(x)把多余的参数舍去。(VC++2008ZQ?
  STR((A,B))?x)被解读为实参?f)Q?A,B)Q而不是被解读Z个实参,W一个是(AW二个是B)?

(3) 有参宏定义中##的用?
#define WIDE(str) L##str
  则会(x)Ş参str的前面加上L
  比如QWIDE("abc")׃(x)被替换成L"abc"
  如果?define FUN(a,b) vo##a##b()
  那么F(tun)UN(id ma,in)?x)被替换成void main()
再比如:(x)
#define s5(a) supper_ ## a
#include <stdio.h>
void supper_printf(const char* p )
{
printf("this is supper printf:\n%s\n",a);
}

int main()
{
s5(printf)("hello owrld");//是调用函数supper_printf.
return 0;
}
(4) 多行宏定义:(x)
  #define doit(m,n) for(int i=0;i<(n);++i)\
  {\
  m+=i;\
  }
关键是要在每一个换行的时候加上一?"\ " ,最后一行不用加。这样用的时候就可以用doitQmQnQ来代替for循环l构?jin)?br />

古月 2011-09-14 23:42 发表评论
]]>
99þùۺϾƷ| þˬˬˬav| þþùƵ| ɫۺϾþþþһ| ۺŮþþ30p| ھƷþþþav| ߳߳þþ| 99þҹɫƷվ| þù˾Ʒ| þĻƷһ| þ99þ99Ʒӿ| ƷŮþþ| þݺҹҹ| þþƷվ| þavСݲ| þþƷһ99| ˾þ111վ| ɫ99þþþø߳ۺӰԺ| 99þۺϺݺۺϾþֹ| þҹ³˿Ƭϼ | ŷþþþ9999| Ұ¾þһ| þƵۿ| ˼˼þúúȾƷ| ˾þƵ| þþƷһԡ| Ʒպþ| þav߳avav紵| ޾Ʒþþþ66| ާѡþþþƷ9966| 99þùһ| avھƷþþþӰԺ| þþһƷ99þþƷ88| þù޾Ʒ| þþþ99ƷƬ| þþùһ| 2022Ʒþþþ| Ʒþþþþô| ݺݾþ| þҹɫƷ鶹 | ˾þô߽AV|