⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 subject_40794.htm

📁 vc
💻 HTM
字号:
<p>
序号:40794 发表者:annehyf1024 发表日期:2003-05-21 16:08:12
<br>主题:怎样在一个函数里返回两个值
<br>内容:CString CZhengshiView::jiequ(int m,CString f)<BR>{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int count1=m++;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int count2=count1;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while((f.GetAt(count2)!=')')&amp;&amp;(f.GetAt(count2)!=','))<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;count2++;(把count2的值传出来)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//j=count2;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CString t;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for(count1;count1&lt;=count2;count1++)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; t=t+f.GetAt(count1);(把字符串t也传出来)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return t;<BR>}<BR>这个函数是从字符串f中截取从m+1开始直到遇见‘,’或‘)’<BR>可用return只能返回一个值(要么return count2,要么ruturn t).怎么把它俩都传出来呢?<BR>
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
回复者:xiongli 回复日期:2003-05-21 17:45:59
<br>内容:传递一个参数的地址进去<BR>在函数中修改这个地址的内容<BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:淡淡 回复日期:2003-05-21 18:01:40
<br>内容:返回值只能有一个,但你可以增加一个函数形参,<BR>比如CString CZhengshiView::jiequ(int m,CString f,int&amp; end)<BR>//引用方式传递end,可以更改end的值<BR>在函数体内增加:end=count2;<BR><BR>使用时:<BR>int end=0,m=1;<BR>CString str="just,now";<BR>CString subStr;<BR>subStr=CZhengshiView::jiequ(m,str,end)<BR>然后你看end的值变化了没有<BR><BR>结果:subStr="ust,";end=4<BR>引用方式不明白看c++书中关于函数参数传递部分
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:金枪鱼 回复日期:2003-05-21 19:55:32
<br>内容:解决的方法:<BR>1、使用函数形参返回;<BR>或者<BR>2、构造一个结构,含有两个字符串成员,然后让函数返回这个结构类型的数据。(如果这个结构有多个成员,则可以通过这个结构返回多个数据了。)<BR><BR>不过一般还是采用函数参数的办法。
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:annehyf1024 回复日期:2003-05-22 15:02:41
<br>内容:金枪鱼,你能不能解释一下使用函数形参返回的方法
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -