c++ - 创建以 C (MFC) 格式化的字符串

标签 c++ visual-studio-2010 mfc

如何在 VC++ (Visual Studio 2010) 中创建格式化字符串?

我可以这样创建:

CString str;
str.Format("%d bla %d", 10, 20);

但我想要这样的东西:

CString str = MACRO_OR_FUNCTION("%d bla %d", 10, 20);

我知道如何实现它,但我更愿意使用它是由 MFC 实现的。

我的问题是:这个宏或函数是在 MFC 中还是在某些标准库中?例如,如果在 MFC 中有它,我将不会实现我的版本。我会更喜欢使用它。

最佳答案

您需要声明一个函数。

CString fn_s_Format( LPCTSTR pctszFormat, ... )
{
    CString s ;

    va_list argList;
    va_start( argList, pctszFormat );
    s.FormatV( pctszFormat, argList );
    va_end( argList );

    return s ;
}

关于c++ - 创建以 C (MFC) 格式化的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11970264/

相关文章:

c++ - 在大页面的 mmap 之后获取 SIGBUS,即使 HugePages_Free 为正

c++ - MFC - 停用除一个按钮以外的所有按钮

c++ - 没有匹配的函数调用未解析的函数类型

visual-studio-2010 - 在 SharePoint 2010 列表定义中隐藏 View 的文件夹结构

c++ - 在 C++ 中检测新设备插入

c++ - 错误 : aggregate 'first one' has incomplete type and cannot be defined

.net-4.0 - 开发 Azure .Net 4.0 应用程序

c# - 进入/调试接口(interface)实现者

c++ - 如何在 MFC 自定义控件中设置控件焦点

c++ - 在运行时决定一个应用程序属于控制台/windows 子系统