c++ - 如何在 CString::Format 中重复一个字符

标签 c++ mfc repeat format-specifiers

我需要在 CString::Format 中重复一个字符。 printf 中的类似内容:

printf("%.*s",10, _T("-"));

result: ----------

如何在 CString::Format 中实现这一点?

sOutput.Format(_T("%.*s"),10,_T("-")); //doesn't work

最佳答案

只需使用适当的 CString 构造函数即可。

CString sOutput(_T('-'), 10);

并且如果您必须将它作为某个较大字符串的一部分以 Format 的形式存在,那么它是相同的

CString sOutput;
sOutput.Format(L"Hello %s", CString(_T('-'), 10).GetString());

关于c++ - 如何在 CString::Format 中重复一个字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42152523/

相关文章:

c++ - 测试适用于成员变量的成员函数

c++ - 如何在 VS 2010 中自动链接依赖项的依赖项?

c++ - SQLite 适合我的游戏吗?

c++ - auto& :的含义

c++ - 如何检查服务器端口是否打开并从 MFC 连接

c++ - 用于 C++ (MFC) 的 SQLite OLE DB 驱动程序

c++ - 如何制作CDialog?

Android GestureDetector onScroll 意外行为

html - 如何水平重复CSS形状?

Java 自定义数组的排列