c++格式说明符不工作

C++ Format Specifier not working

本文关键字:工作 说明符 格式 c++      更新时间:2023-10-16

在portaudio回调中,我正在运行循环直到framesperbuffer变量。通过调试,名为的for循环变量cnt是递增的,但格式说明符先打印256,然后打印0。即使我使用tmp.Format(_TEXT("-%d-",3),我在CString中得到0。

这是我的一段代码,我使用visual studio 2010,也尝试了_T和_TEXT没有错误生成

float *inp=(float*)inputBuffer;
    float *outp=(float*)outputBuffer;
    CString  str;
    CString  tmp;
    for(unsigned int cnt=0; cnt< framesPerBuffer; cnt++)
    {
    tmp.Format(_TEXT("-%d-",cnt));
    str.Append(tmp);
    }

只是一个放错位置的父级。在_TEXT()宏参数列表中有一个int参数给Format,所以它根本没有被传递给Format

这个应该会更好:

tmp.Format(_TEXT("-%d-"),cnt);