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

📄 subject_27595.htm

📁 一些关于vc的问答
💻 HTM
字号:
<p>
序号:27595 发表者:阿飞 发表日期:2003-01-13 19:00:58
<br>主题:CString 问题
<br>内容:CString str;<BR>sprintf (str, "%s", string);<BR>上面的函数中,用str作第一个参数会出错,如果一定用CString 类型的变量又不出错,该怎么办呢?
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:晚风也渡 回复日期:2003-01-13 19:09:44
<br>内容:可以用str.format("%s",string);<BR>这个函数的作用于sprintf是一样的。<BR>具体用法可查看MSDN
<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-01-13 19:16:34
<br>内容:to 晚风也渡 :<BR><BR>如果要控制string 的长度该怎么办?
<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-01-13 19:43:08
<br>内容:和sprintf一样,在第三个参数写出长度就可以了<BR>下面的摘自MSDN:<BR>CString::Format<BR>void Format( LPCTSTR lpszFormat, ... );<BR><BR>void Format( UINT nFormatID, ... );<BR><BR>Parameters<BR><BR>lpszFormat<BR><BR>A format-control string.<BR><BR>nFormatID<BR><BR>The string resource identifier that contains the format-control string. <BR><BR>Remarks<BR><BR>Call this member function to write formatted data to a CString in the same way that sprintf formats data into a C-style character array. This function formats and stores a series of characters and values in the CString. Each optional argument (if any) is converted and output according to the corresponding format specification in lpszFormat or from the string resource identified by nFormatID. <BR><BR>The call will fail if the string object itself is offered as a parameter to Format. For example, the following code:<BR><BR>CString str = "Some Data";<BR>str.Format("%s%d", str, 123);&nbsp;&nbsp; // Attention: str is also used in the parameter list.<BR><BR>will cause unpredictable results.<BR><BR>When you pass a character string as an optional argument, you must cast it explicitly as LPCTSTR. The format has the same form and function as the format argument for the printf function. (For a description of the format and arguments, seeprintf in the Run-Time Library Reference.) A null character is appended to the end of the characters written.<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>
回复者:tiger_bai 回复日期:2003-01-13 20:23:10
<br>内容:用 sprintf()函数!长度自己设定
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:su_37 回复日期:2003-01-14 09:17:05
<br>内容:CString str;<BR><BR>str.Format(_T("Floating point: %.2f\n"), 12345.12345);<BR>_tprintf("%s", (LPCTSTR) str);<BR><BR>str.Format(_T("Left-justified integer: %.6d\n"), 35);<BR>_tprintf("%s", (LPCTSTR) str);<BR><BR>str.Format(IDS_SCORE, 5, 3);<BR>_tprintf("%s", (LPCTSTR) str);
<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 + -