﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-天涯浪子</title><link>http://www.cppblog.com/junfeng568/</link><description>==&gt;&gt;多情总被无情伤，此生无情又何妨！ 红豆本是相思子，一寸相思一寸灰。此生不能续旧盟，必当续之于来生。</description><language>zh-cn</language><lastBuildDate>Thu, 23 Apr 2026 10:07:40 GMT</lastBuildDate><pubDate>Thu, 23 Apr 2026 10:07:40 GMT</pubDate><ttl>60</ttl><item><title>如何查看系统变量</title><link>http://www.cppblog.com/junfeng568/archive/2006/03/18/4326.html</link><dc:creator>天涯浪子</dc:creator><author>天涯浪子</author><pubDate>Sat, 18 Mar 2006 14:01:00 GMT</pubDate><guid>http://www.cppblog.com/junfeng568/archive/2006/03/18/4326.html</guid><wfw:comment>http://www.cppblog.com/junfeng568/comments/4326.html</wfw:comment><comments>http://www.cppblog.com/junfeng568/archive/2006/03/18/4326.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/junfeng568/comments/commentRss/4326.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/junfeng568/services/trackbacks/4326.html</trackback:ping><description><![CDATA[<p>//该程序用来查看自己的系统环境,相当于在命令行输入env所显示的结果.<br />#include &lt;iostream&gt;<br />using namespace std;</p>
		<p>int main( int argc , char* argv[] , char* env[] ){//也可写成int main(int argc,char* *argv,char* *env[]){<br />  //int argc表示命令行参数的个数,<br />  //char* argv[]表示命令行参数的值<br /> cout&lt;&lt;"begin ..." &lt;&lt; endl;<br /> while( env!=NULL &amp;&amp; *env != NULL ){// 二者是等价的while(env&amp;&amp;*env){<br />  cout&lt;&lt; *env &lt;&lt; endl;<br />  env++;<br /> }<br /> cout&lt;&lt;"end  ...." &lt;&lt; endl;<br /> return 0 ;<br />}</p><img src ="http://www.cppblog.com/junfeng568/aggbug/4326.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/junfeng568/" target="_blank">天涯浪子</a> 2006-03-18 22:01 <a href="http://www.cppblog.com/junfeng568/archive/2006/03/18/4326.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>如何取得自己机子的环境变量</title><link>http://www.cppblog.com/junfeng568/archive/2006/03/18/4324.html</link><dc:creator>天涯浪子</dc:creator><author>天涯浪子</author><pubDate>Sat, 18 Mar 2006 13:59:00 GMT</pubDate><guid>http://www.cppblog.com/junfeng568/archive/2006/03/18/4324.html</guid><wfw:comment>http://www.cppblog.com/junfeng568/comments/4324.html</wfw:comment><comments>http://www.cppblog.com/junfeng568/archive/2006/03/18/4324.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/junfeng568/comments/commentRss/4324.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/junfeng568/services/trackbacks/4324.html</trackback:ping><description><![CDATA[<p>/*变量p用来存放自己定义的环境变量,而pt用来存放系统环境变量的PATH值<br />注意:此例应该先判断变量的返回值是否为空<br />取得环境变量函数的格式如下:<br /> char* getenv(const char *name); return value for environment name.<br /> <br /> int putenv(const char* str); change or add value to environment.<br />*/<br />#include &lt;stdlib.h&gt;<br />#include &lt;iostream&gt;<br />using namespace std;</p>
		<p>int main(){<br /> char *p = NULL;<br /> char *pt=NULL;<br /> <br /> p = getenv( "AAA" );<br /> pt =getenv("PATH");<br /> <br /> if( p == NULL )<br />  cout&lt;&lt;"No such env named AAA"&lt;&lt;endl;<br /> else<br />  cout&lt;&lt;"AAA=" &lt;&lt; p &lt;&lt; endl;<br /> if( pt == NULL )<br />  cout&lt;&lt;"No such env named PATH"&lt;&lt;endl;<br /> else<br />  cout&lt;&lt;"PATH=" &lt;&lt; pt&lt;&lt; endl;<br /> putenv( "AAA=123456" );<br /> cout&lt;&lt;"AAA=" &lt;&lt; getenv( "AAA" ) &lt;&lt; endl;<br /> putenv("AAA=123");<br /> cout&lt;&lt;"AAA="&lt;&lt;getenv("AAA")&lt;&lt;endl;<br /> <br /> cout&lt;&lt;"PATH="&lt;&lt;getenv("PATH")&lt;&lt;endl;<br /> return 0 ;<br />}</p>
		<p>/*问题:<br /> 假如环境变量YU在用户的shell下的值是123456,在我们的应用程序中<br /> 通过getenv()和putenv()来更改该环境变量为abcdef,那么当我们结束应用<br /> 程序后回到shell下时,我们用命令echo $YU,那么结果应该是什么?<br />*/</p><img src ="http://www.cppblog.com/junfeng568/aggbug/4324.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/junfeng568/" target="_blank">天涯浪子</a> 2006-03-18 21:59 <a href="http://www.cppblog.com/junfeng568/archive/2006/03/18/4324.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>高级进程通信技术------IPC通信</title><link>http://www.cppblog.com/junfeng568/archive/2006/03/14/4151.html</link><dc:creator>天涯浪子</dc:creator><author>天涯浪子</author><pubDate>Tue, 14 Mar 2006 12:50:00 GMT</pubDate><guid>http://www.cppblog.com/junfeng568/archive/2006/03/14/4151.html</guid><wfw:comment>http://www.cppblog.com/junfeng568/comments/4151.html</wfw:comment><comments>http://www.cppblog.com/junfeng568/archive/2006/03/14/4151.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/junfeng568/comments/commentRss/4151.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/junfeng568/services/trackbacks/4151.html</trackback:ping><description><![CDATA[<P>一。有关的系统命令<BR>&nbsp;//以下是在unix下进行的操作<BR>&nbsp;1。ipcs<BR>&nbsp;执行结果如下：<BR>&nbsp;IPC status from &lt;running system&gt; as of 2006年03月13日 星期一 16时38分56秒 CST<BR>T&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ID&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; KEY&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MODE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OWNER&nbsp;&nbsp;&nbsp; GROUP<BR>Message Queues:<BR>Shared Memory:<BR>m&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0&nbsp;&nbsp; 0x50000d2b --rw-r--r--&nbsp;&nbsp;&nbsp;&nbsp; root&nbsp;&nbsp;&nbsp;&nbsp; root<BR>Semaphores:<BR>s&nbsp;&nbsp;&nbsp;&nbsp; 131075&nbsp;&nbsp; 0x123455&nbsp;&nbsp; --ra-------&nbsp; yuqiang&nbsp;&nbsp;&nbsp; staff</P>
<P>&nbsp;2.ipcrm -q/m/s&nbsp; ID号<BR>&nbsp;作用 ：remove a message queue ,semaphore set ,or shared memory ID.<BR>&nbsp;执行命令ipcrm -s 131075后，结果如下：<BR>&nbsp;IPC status from &lt;running system&gt; as of 2006年03月13日 星期一 16时36分26秒 CST<BR>T&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ID&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; KEY&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MODE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OWNER&nbsp;&nbsp;&nbsp; GROUP<BR>Message Queues:<BR>Shared Memory:<BR>m&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0&nbsp;&nbsp; 0x50000d2b --rw-r--r--&nbsp;&nbsp;&nbsp;&nbsp; root&nbsp;&nbsp;&nbsp;&nbsp; root<BR>Semaphores:</P><img src ="http://www.cppblog.com/junfeng568/aggbug/4151.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/junfeng568/" target="_blank">天涯浪子</a> 2006-03-14 20:50 <a href="http://www.cppblog.com/junfeng568/archive/2006/03/14/4151.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>今晚上新的内容</title><link>http://www.cppblog.com/junfeng568/archive/2006/03/14/4116.html</link><dc:creator>天涯浪子</dc:creator><author>天涯浪子</author><pubDate>Tue, 14 Mar 2006 00:19:00 GMT</pubDate><guid>http://www.cppblog.com/junfeng568/archive/2006/03/14/4116.html</guid><wfw:comment>http://www.cppblog.com/junfeng568/comments/4116.html</wfw:comment><comments>http://www.cppblog.com/junfeng568/archive/2006/03/14/4116.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/junfeng568/comments/commentRss/4116.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/junfeng568/services/trackbacks/4116.html</trackback:ping><description><![CDATA[<P>呵呵，大家好呀，由于这几天很累，也没写什么新的内容，所以决定今天晚上再来一些新的东西，希望大家多提宝贵的意见，同时在此感谢&nbsp; 沐枫同志，他给的建议不错。</P><img src ="http://www.cppblog.com/junfeng568/aggbug/4116.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/junfeng568/" target="_blank">天涯浪子</a> 2006-03-14 08:19 <a href="http://www.cppblog.com/junfeng568/archive/2006/03/14/4116.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>memset ,memcpy 和strcpy 的根本区别？</title><link>http://www.cppblog.com/junfeng568/archive/2006/03/11/4022.html</link><dc:creator>天涯浪子</dc:creator><author>天涯浪子</author><pubDate>Sat, 11 Mar 2006 14:00:00 GMT</pubDate><guid>http://www.cppblog.com/junfeng568/archive/2006/03/11/4022.html</guid><wfw:comment>http://www.cppblog.com/junfeng568/comments/4022.html</wfw:comment><comments>http://www.cppblog.com/junfeng568/archive/2006/03/11/4022.html#Feedback</comments><slash:comments>18</slash:comments><wfw:commentRss>http://www.cppblog.com/junfeng568/comments/commentRss/4022.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/junfeng568/services/trackbacks/4022.html</trackback:ping><description><![CDATA[<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 21pt; TEXT-INDENT: 27.95pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-para-margin-left: 2.0gd; mso-char-indent-count: 1.99" align=left><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US style="FONT-SIZE: 14pt; mso-fareast-font-family: 仿宋_GB2312; mso-font-kerning: 0pt">Memset<SPAN style="mso-spacerun: yes">&nbsp; </SPAN></SPAN></B><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 仿宋_GB2312; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'">用来对一段内存空间全部设置为某个字符，一般用在对定义的字符串进行初始化为</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; mso-fareast-font-family: 仿宋_GB2312; mso-font-kerning: 0pt">‘ ’</SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 仿宋_GB2312; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'">或</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; mso-fareast-font-family: 仿宋_GB2312; mso-font-kerning: 0pt">‘\<?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" /><st1:chmetcnv w:st="on" UnitName="’" SourceValue="0" HasSpace="False" Negative="False" NumberType="1" TCSC="0">0’</st1:chmetcnv></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 仿宋_GB2312; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'">；</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; mso-fareast-font-family: 仿宋_GB2312; mso-font-kerning: 0pt"><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 21pt; TEXT-INDENT: 27pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-para-margin-left: 2.0gd; mso-char-indent-count: 2.25" align=left><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 仿宋_GB2312; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'">例</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; mso-fareast-font-family: 仿宋_GB2312; mso-font-kerning: 0pt">:char a[100];memset(a, '\0', sizeof(a));<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 21pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; mso-fareast-font-family: 仿宋_GB2312; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;</SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>memset</SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 仿宋_GB2312; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'">可以方便的清空一个结构类型的变量或数组。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; mso-fareast-font-family: 仿宋_GB2312; mso-font-kerning: 0pt"> <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 24pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-char-indent-count: 2.0" align=left><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 仿宋_GB2312; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'">如：</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; mso-fareast-font-family: 仿宋_GB2312; mso-font-kerning: 0pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 53.75pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-para-margin-left: 5.12gd" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; mso-fareast-font-family: 仿宋_GB2312; mso-font-kerning: 0pt">struct sample_struct<BR>{<BR>&nbsp;char &nbsp; csName[16];<BR>&nbsp;int &nbsp; &nbsp;iSeq;<BR>&nbsp;int &nbsp; &nbsp;iType;<BR>};<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 21pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-para-margin-left: 2.0gd" align=left><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 仿宋_GB2312; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'">对于变量</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; mso-fareast-font-family: 仿宋_GB2312; mso-font-kerning: 0pt"><BR>struct sample_strcut &nbsp;stTest; <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 21pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-para-margin-left: 2.0gd" align=left><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 仿宋_GB2312; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'">一般情况下，清空</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; mso-fareast-font-family: 仿宋_GB2312; mso-font-kerning: 0pt">stTest</SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 仿宋_GB2312; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'">的方法：</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; mso-fareast-font-family: 仿宋_GB2312; mso-font-kerning: 0pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 21pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-para-margin-left: 2.0gd" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; mso-fareast-font-family: 仿宋_GB2312; mso-font-kerning: 0pt">stTest.csName[0]='\0';<BR>stTest.iSeq=0;<BR>stTest.iType=0; <o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 21pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-para-margin-left: 2.0gd" align=left><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 仿宋_GB2312; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'">用</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; mso-fareast-font-family: 仿宋_GB2312; mso-font-kerning: 0pt">memset</SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 仿宋_GB2312; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'">就非常方便：</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; mso-fareast-font-family: 仿宋_GB2312; mso-font-kerning: 0pt"><BR>memset(&amp;stTest,0,sizeof(struct sample_struct));<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 21pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-para-margin-left: 2.0gd" align=left><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 仿宋_GB2312; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'">如果是数组：</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; mso-fareast-font-family: 仿宋_GB2312; mso-font-kerning: 0pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 21pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-para-margin-left: 2.0gd" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; mso-fareast-font-family: 仿宋_GB2312; mso-font-kerning: 0pt"><SPAN style="mso-spacerun: yes">&nbsp;</SPAN>struct sample_struct &nbsp; TEST[10];<BR></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 仿宋_GB2312; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'">则</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; mso-fareast-font-family: 仿宋_GB2312; mso-font-kerning: 0pt"><BR>memset(TEST,0,sizeof(struct sample_struct)*10);<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 21pt; TEXT-INDENT: 35pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-para-margin-left: 2.0gd; mso-char-indent-count: 2.49" align=left><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US style="FONT-SIZE: 14pt; mso-fareast-font-family: 仿宋_GB2312; mso-font-kerning: 0pt">memcpy<SPAN style="mso-spacerun: yes">&nbsp; </SPAN></SPAN></B><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 仿宋_GB2312; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'">用来做内存拷贝，你可以拿它拷贝任何数据类型的对象，可以指定拷贝的数据长度。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; mso-fareast-font-family: 仿宋_GB2312; mso-font-kerning: 0pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 21pt; TEXT-INDENT: 23.9pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-para-margin-left: 2.0gd; mso-char-indent-count: 1.99" align=left><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 仿宋_GB2312; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'">例：</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; mso-fareast-font-family: 仿宋_GB2312; mso-font-kerning: 0pt">char a[100],b[50]; memcpy(b, a, sizeof(b));</SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 仿宋_GB2312; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'">注意如用</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; mso-fareast-font-family: 仿宋_GB2312; mso-font-kerning: 0pt">sizeof(a)</SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 仿宋_GB2312; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'">，会造成</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; mso-fareast-font-family: 仿宋_GB2312; mso-font-kerning: 0pt">b</SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 仿宋_GB2312; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'">的内存地址溢出。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; mso-fareast-font-family: 仿宋_GB2312; mso-font-kerning: 0pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 56.2pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-char-indent-count: 4.0" align=left><B style="mso-bidi-font-weight: normal"><SPAN lang=EN-US style="FONT-SIZE: 14pt; mso-fareast-font-family: 仿宋_GB2312; mso-font-kerning: 0pt">Strcpy<SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN></SPAN></B><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 仿宋_GB2312; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'">就只能拷贝字符串了，它遇到</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; mso-fareast-font-family: 仿宋_GB2312; mso-font-kerning: 0pt">'\0'</SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 仿宋_GB2312; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'">就结束拷贝。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; mso-fareast-font-family: 仿宋_GB2312; mso-font-kerning: 0pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 21pt; TEXT-INDENT: 33pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-para-margin-left: 2.0gd; mso-char-indent-count: 2.75" align=left><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 仿宋_GB2312; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'">例：</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; mso-fareast-font-family: 仿宋_GB2312; mso-font-kerning: 0pt">char a[100],b[50];strcpy(a,b);</SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 仿宋_GB2312; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'">如用</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; mso-fareast-font-family: 仿宋_GB2312; mso-font-kerning: 0pt">strcpy(b,a)</SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 仿宋_GB2312; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'">，要注意</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; mso-fareast-font-family: 仿宋_GB2312; mso-font-kerning: 0pt">a</SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 仿宋_GB2312; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'">中的字符串长度（第一个</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; mso-fareast-font-family: 仿宋_GB2312; mso-font-kerning: 0pt">‘\<st1:chmetcnv w:st="on" UnitName="’" SourceValue="0" HasSpace="False" Negative="False" NumberType="1" TCSC="0">0’</st1:chmetcnv></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 仿宋_GB2312; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'">之前）是否超过</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; mso-fareast-font-family: 仿宋_GB2312; mso-font-kerning: 0pt">50</SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 仿宋_GB2312; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'">位，如超过，则会造成</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; mso-fareast-font-family: 仿宋_GB2312; mso-font-kerning: 0pt">b</SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 仿宋_GB2312; mso-font-kerning: 0pt; mso-ascii-font-family: 'Times New Roman'">的内存地址溢出。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; mso-fareast-font-family: 仿宋_GB2312; mso-font-kerning: 0pt"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 21pt; TEXT-INDENT: 36pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-para-margin-left: 2.0gd; mso-char-indent-count: 3.0" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; mso-fareast-font-family: 仿宋_GB2312">str</SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 仿宋_GB2312; mso-ascii-font-family: 'Times New Roman'">也可以用用个参数的</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; mso-fareast-font-family: 仿宋_GB2312">strncpy(a,b,n)<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 21pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-para-margin-left: 2.0gd" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; mso-fareast-font-family: 仿宋_GB2312">========================================================<o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 21pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-para-margin-left: 2.0gd" align=left><SPAN lang=EN-US style="FONT-SIZE: 12pt; mso-fareast-font-family: 仿宋_GB2312">memset</SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 仿宋_GB2312; mso-ascii-font-family: 'Times New Roman'">主要应用是初始化某个内存空间。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; mso-fareast-font-family: 仿宋_GB2312"><BR>memcpy</SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 仿宋_GB2312; mso-ascii-font-family: 'Times New Roman'">是用于</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; mso-fareast-font-family: 仿宋_GB2312">copy</SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 仿宋_GB2312; mso-ascii-font-family: 'Times New Roman'">源空间的数据到目的空间中。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; mso-fareast-font-family: 仿宋_GB2312"><BR>strcpy</SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 仿宋_GB2312; mso-ascii-font-family: 'Times New Roman'">用于字符串</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; mso-fareast-font-family: 仿宋_GB2312">copy,</SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 仿宋_GB2312; mso-ascii-font-family: 'Times New Roman'">遇到</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; mso-fareast-font-family: 仿宋_GB2312">‘\<st1:chmetcnv w:st="on" UnitName="’" SourceValue="0" HasSpace="False" Negative="False" NumberType="1" TCSC="0">0’</st1:chmetcnv></SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 仿宋_GB2312; mso-ascii-font-family: 'Times New Roman'">，将结束。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; mso-fareast-font-family: 仿宋_GB2312"><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt 21pt; TEXT-ALIGN: left; mso-pagination: widow-orphan; mso-para-margin-left: 2.0gd" align=left><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 仿宋_GB2312; mso-ascii-font-family: 'Times New Roman'">如果你理解了这些，你应该知道他们的区别：例如你初始化某块空间的时候，用到</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; mso-fareast-font-family: 仿宋_GB2312">memcpy</SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 仿宋_GB2312; mso-ascii-font-family: 'Times New Roman'">，那么应该怎么写，是不是显得很笨。</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; mso-fareast-font-family: 仿宋_GB2312"><BR><SPAN style="mso-spacerun: yes">&nbsp; </SPAN>int &nbsp;m[100]<BR>memset((void*)m,0x00,sizeof(int)*100);//Ok</SPAN><SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 仿宋_GB2312; mso-ascii-font-family: 'Times New Roman'">！</SPAN><SPAN lang=EN-US style="FONT-SIZE: 12pt; mso-fareast-font-family: 仿宋_GB2312"><BR>memcpy((void*)m,"\0\0\0\0....",sizeof(int)*100);//it’s wrong.<o:p></o:p></SPAN></P><img src ="http://www.cppblog.com/junfeng568/aggbug/4022.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/junfeng568/" target="_blank">天涯浪子</a> 2006-03-11 22:00 <a href="http://www.cppblog.com/junfeng568/archive/2006/03/11/4022.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>有关C++技术文章的安排</title><link>http://www.cppblog.com/junfeng568/archive/2006/03/08/3909.html</link><dc:creator>天涯浪子</dc:creator><author>天涯浪子</author><pubDate>Wed, 08 Mar 2006 13:30:00 GMT</pubDate><guid>http://www.cppblog.com/junfeng568/archive/2006/03/08/3909.html</guid><wfw:comment>http://www.cppblog.com/junfeng568/comments/3909.html</wfw:comment><comments>http://www.cppblog.com/junfeng568/archive/2006/03/08/3909.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/junfeng568/comments/commentRss/3909.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/junfeng568/services/trackbacks/3909.html</trackback:ping><description><![CDATA[&nbsp; 关于C++的文章，主要分为以下几部分：<BR>1。关于C++的基础部分<BR>2。在Unix环境下的C++编程<BR>3。用C++访问数据库，即Pro*C技术<BR>4。最后就是网络编程了<BR>5.有关UNIX的基本知识将放在我的JAVA博客里，相关链接是<A href="http://blog.sina.com.cn/u/1220290933">http://blog.sina.com.cn/u/1220290933</A><BR>同时，希望朋友们多提宝贵意见，以弥补我的不足，同时，由于时间有限，每天写的东西不多而且不详细，我会在以后的时间里，逐步完善，同时希望朋友们多提宝贵意见。另外，在<FONT style="BACKGROUND-COLOR: #006400" face="Courier New" size=5><STRONG>友情链接</STRONG></FONT>里还有关于Java方面的博客，欢迎你的到来。<img src ="http://www.cppblog.com/junfeng568/aggbug/3909.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/junfeng568/" target="_blank">天涯浪子</a> 2006-03-08 21:30 <a href="http://www.cppblog.com/junfeng568/archive/2006/03/08/3909.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title> 数组变量</title><link>http://www.cppblog.com/junfeng568/archive/2006/03/08/3906.html</link><dc:creator>天涯浪子</dc:creator><author>天涯浪子</author><pubDate>Wed, 08 Mar 2006 11:54:00 GMT</pubDate><guid>http://www.cppblog.com/junfeng568/archive/2006/03/08/3906.html</guid><wfw:comment>http://www.cppblog.com/junfeng568/comments/3906.html</wfw:comment><comments>http://www.cppblog.com/junfeng568/archive/2006/03/08/3906.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/junfeng568/comments/commentRss/3906.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/junfeng568/services/trackbacks/3906.html</trackback:ping><description><![CDATA[前面介绍的变量只能进行单个数据的操作,若所用的SQL语句的输出结果有许多时,这时候就<BR>可以用数组变量来存取.<BR>1.注意事项:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (1)Pro*C只支持一维数组,但char类型除外,它可以支持二维数组.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (2)Pro*C不支持数组指针.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (3)Pro*C所支持的最大维数是32767.<BR>2.数组变量的声明也声明成宿主变量的形式.如:<BR>&nbsp;&nbsp;&nbsp; EXEC SQL BEGIN DECLARE SECTION<BR>&nbsp;&nbsp;&nbsp; char&nbsp; pwd[50];<BR>&nbsp;&nbsp;&nbsp; char v_name[100];<BR>&nbsp;&nbsp;&nbsp; EXEC SQL END DECLARE SECTION<BR>3.如何在SQL语句中使用数组变量?<BR>&nbsp;只需要给出:和变量名称,不要个下标.通过SQL语句查出的数据会自动排列.<BR>&nbsp;EXEC SQL BEGIN DECLARE SECTION;<BR>&nbsp;char pwd[ 30 ] ;<BR>&nbsp;char v_l_name[ 100 ] ;<BR>&nbsp;short ind_l_name ;<BR>&nbsp;EXEC SQL END DECLARE SECTION;<BR>&nbsp;................................<BR>&nbsp;................................<BR>&nbsp;EXEC SQL select last_name <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; INTO :v_l_name :ind_l_name<BR>&nbsp;&nbsp; from emp<BR>&nbsp;&nbsp; where id=1 ;<BR>&nbsp;&nbsp; <BR>&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 以下的例子是错误的 :<BR>&nbsp; for(int i=0;i&lt;100;i++)<BR>&nbsp; {<BR>&nbsp; &nbsp;EXEC SQL select last_name <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; INTO :v_l_name[i] :ind_l_name[i]<BR>&nbsp;&nbsp;from emp<BR>&nbsp;&nbsp;where id=1 ; <BR>&nbsp; }<BR>4.指示变量也可以定义成数组,但元素数应大于或等于数组变量数.如下例子:<BR>&nbsp;EXEC SQL BEGIN DECLARE SECTION;<BR>&nbsp;int emp_number[100];<BR>&nbsp;short ind_emp_number[100];//此处的指示变量数不能少于数组变量数.<BR>&nbsp;char emp_name[100][15];<BR>&nbsp;EXEC SQL END DECLARE SECTION;<img src ="http://www.cppblog.com/junfeng568/aggbug/3906.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/junfeng568/" target="_blank">天涯浪子</a> 2006-03-08 19:54 <a href="http://www.cppblog.com/junfeng568/archive/2006/03/08/3906.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>指示变量</title><link>http://www.cppblog.com/junfeng568/archive/2006/03/07/3880.html</link><dc:creator>天涯浪子</dc:creator><author>天涯浪子</author><pubDate>Tue, 07 Mar 2006 15:56:00 GMT</pubDate><guid>http://www.cppblog.com/junfeng568/archive/2006/03/07/3880.html</guid><wfw:comment>http://www.cppblog.com/junfeng568/comments/3880.html</wfw:comment><comments>http://www.cppblog.com/junfeng568/archive/2006/03/07/3880.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/junfeng568/comments/commentRss/3880.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/junfeng568/services/trackbacks/3880.html</trackback:ping><description><![CDATA[<P>1.指示变量用于处理数据库的NULL值,监督和管理与其相关联的宿主变量,是短整型变量(short).<BR>2.一个指示变量只管理一个宿主变量,指示变量紧跟在宿主变量后面.<BR>3.语法结构有两种方式:<BR>&nbsp;(1):host_variable INDICATOR :indicator_varible<BR>&nbsp;(2):host_variable : indicator_variable//习惯上常用此种方法<BR>4.指示变量的作用:<BR>&nbsp;&nbsp;&nbsp; 主要用在输出,即当宿主变量用于接收数据库的返回数据时.通过在宿主变量后用指示变量,<BR>&nbsp;&nbsp;&nbsp; 检测是否返回了NULL.<BR>&nbsp;&nbsp;&nbsp; -1:表示数据库表列的值为NULL<BR>&nbsp;&nbsp;&nbsp; =0:将原值原封不动的赋给宿主变量.<BR>&nbsp;&nbsp;&nbsp; &gt;0:将数据库表列的值截断后赋给宿主变量,指示变量值为该列值的原始长度.<BR>5.指示变量的例子如下:<BR>习惯上一般在声明宿主变量的时候在其前面加v_,在声明指示变量时候在其前面加ind_.<BR>#include &lt;iostream&gt;<BR>using namespace std;<BR>EXEC SQL INCLUDE SQLCA;</P>
<P>//声明宿主变量<BR>EXEC SQL BEGIN DECLARE SECTION;<BR>char pwd[ 30 ] ;<BR>char v_l_name[ 100 ] ;<BR>short ind_l_name ;<BR>EXEC SQL END DECLARE SECTION;</P>
<P>int main(){<BR>&nbsp;EXEC SQL WHENEVER SQLERROR STOP ;//说明对sqlerror的处理方式<BR>&nbsp;//连接数据库<BR>&nbsp;cout&lt;&lt;"enter username and passwd&gt;";<BR>&nbsp;cin&gt;&gt;pwd ;<BR>&nbsp;EXEC SQL CONNECT :pwd;<BR>&nbsp;cout&lt;&lt;"connect db using "&lt;&lt; pwd&lt;&lt;" ok."&lt;&lt;endl;</P>
<P>&nbsp;EXEC SQL select last_name <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; into :v_l_name :ind_l_name<BR>&nbsp;&nbsp; from emp<BR>&nbsp;&nbsp; where id=1 ;<BR>&nbsp;//通过指示变量来判断宿主变量的值是否为NULL,并进行输出处理.<BR>&nbsp;if( ind_l_name == -1 ){<BR>&nbsp;&nbsp;cout&lt;&lt;"-- NULL --" &lt;&lt; endl;<BR>&nbsp;}else if( ind_l_name &gt; 0 ){<BR>&nbsp;&nbsp;cout&lt;&lt; v_l_name &lt;&lt;"..."&lt;&lt; endl;<BR>&nbsp;}else{<BR>&nbsp;&nbsp;cout&lt;&lt;"last name=&gt;" &lt;&lt; v_l_name &lt;&lt; endl;<BR>&nbsp;}<BR>&nbsp;<BR>&nbsp;//完成SQL语句并释放内存.<BR>&nbsp;EXEC SQL COMMIT WORK RELEASE ;<BR>&nbsp;return 0 ;<BR>}</P><img src ="http://www.cppblog.com/junfeng568/aggbug/3880.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/junfeng568/" target="_blank">天涯浪子</a> 2006-03-07 23:56 <a href="http://www.cppblog.com/junfeng568/archive/2006/03/07/3880.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Pro*C的预编译程序</title><link>http://www.cppblog.com/junfeng568/archive/2006/03/07/3868.html</link><dc:creator>天涯浪子</dc:creator><author>天涯浪子</author><pubDate>Tue, 07 Mar 2006 12:41:00 GMT</pubDate><guid>http://www.cppblog.com/junfeng568/archive/2006/03/07/3868.html</guid><wfw:comment>http://www.cppblog.com/junfeng568/comments/3868.html</wfw:comment><comments>http://www.cppblog.com/junfeng568/archive/2006/03/07/3868.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/junfeng568/comments/commentRss/3868.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/junfeng568/services/trackbacks/3868.html</trackback:ping><description><![CDATA[<STRONG>5.Pro*C的预编译程序<BR></STRONG>&nbsp;目的:完成Pro*C源程序到纯C源程序的转换.<BR>&nbsp;常用的预编译选项:<BR>&nbsp;(1)INAME=path and filename(预编译文件的输入名字)<BR>&nbsp;(2)ONAME=path and filename(预编译文件的输出名字)<BR>&nbsp;(3)INCLUDE=path(头文件所在的路径)<BR>&nbsp;=====&gt;多个头文件表达INCLUDE=(路径名1,路径名2.......)<BR>&nbsp;(4)PARSE=FULL|PARTIA|NONE(default is FULL for C, Other&nbsp; is for C++)<BR>&nbsp;&nbsp;当为C++时一般用NONE.<BR>&nbsp;(5)CODE=ANSI_C|CPP(default is ANSI_C),当为C++时用CPP.<BR>&nbsp;(6)USERID=username/password<BR>&nbsp;(7)SQLCHECK 用于是否对SQL语法作检测. <BR>(8)MODE=ANSI|ORACLE(oracle is default.)<img src ="http://www.cppblog.com/junfeng568/aggbug/3868.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/junfeng568/" target="_blank">天涯浪子</a> 2006-03-07 20:41 <a href="http://www.cppblog.com/junfeng568/archive/2006/03/07/3868.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Pro*C的基本结构</title><link>http://www.cppblog.com/junfeng568/archive/2006/03/07/3867.html</link><dc:creator>天涯浪子</dc:creator><author>天涯浪子</author><pubDate>Tue, 07 Mar 2006 12:40:00 GMT</pubDate><guid>http://www.cppblog.com/junfeng568/archive/2006/03/07/3867.html</guid><wfw:comment>http://www.cppblog.com/junfeng568/comments/3867.html</wfw:comment><comments>http://www.cppblog.com/junfeng568/archive/2006/03/07/3867.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/junfeng568/comments/commentRss/3867.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/junfeng568/services/trackbacks/3867.html</trackback:ping><description><![CDATA[<P><STRONG>3.下面从Pro*C的一个简单程序入手:</STRONG><BR>#include &lt;iostream&gt;<BR>using namespace std;<BR>EXEC SQL INCLUDE SQLCA;</P>
<P>EXEC SQL BEGIN DECLARE SECTION;<BR>char username[30];<BR>char password[20];<BR>char last_name[30];<BR>EXEC SQL END DECLARE SECTION;</P>
<P>void sqlerror();<BR>main()<BR>{<BR>&nbsp;EXEC SQL WHENEVER SQLERROR<BR>&nbsp;&nbsp;DO sqlerror();<BR>&nbsp;strcpy(username,"langzi");<BR>&nbsp;strcpy(password,"langzi");<BR>&nbsp;EXEC SQL CONNECT:username<BR>&nbsp;IDENTIFIED BY:password;<BR>&nbsp;EXEC SQL select LAST_NAME<BR>&nbsp;&nbsp;&nbsp; into:last_name from S_EMP where id=2;<BR>&nbsp;&nbsp;&nbsp; printf("\nID=2,last_name=%s\n",last_name);<BR>}<BR>void sqlerror()<BR>{<BR>&nbsp;EXEC SQL WHENEVER SQLERROR<BR>&nbsp;CONTINUE;<BR>&nbsp;&nbsp;printf("\n=&gt;oracle error detected:\n");<BR>&nbsp;&nbsp;printf("%.60s\n",sqlca.sqlerrm.sqlerrmc);<BR>&nbsp;EXEC SQL ROLLBACK WORK RELEASE;<BR>&nbsp;exit(1);<BR>}<BR><STRONG>4.从上面的程序简要看一下其结构:<BR></STRONG>&nbsp;&nbsp;&nbsp; (1)include头文件(包括c/c++和Pro*C/C++)<BR>&nbsp;&nbsp;&nbsp; (2)定义变量<BR>&nbsp;&nbsp;&nbsp; (3)定义函数<BR>&nbsp;&nbsp;&nbsp; (4)写主方法main<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 联接数据库:connect<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SQL操作语句:EXEC SQL..........;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exception<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 断开联接,释放连接:EXEC SQL COMMIT/ROLLBACK WORK RELEASE<BR></P><img src ="http://www.cppblog.com/junfeng568/aggbug/3867.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/junfeng568/" target="_blank">天涯浪子</a> 2006-03-07 20:40 <a href="http://www.cppblog.com/junfeng568/archive/2006/03/07/3867.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>