改正错误

时间:2018-04-01 08:18:12

标签: c++

为什么不编译此代码?

TextMem tmem, *fp = &tmem;
char *_res = new char[textbuf.mLength + 1];

tmem.Open(textbuf, TextStream::READ | TextStream::EOL_CRLF | TextStream::EOL_ORPHAN_CR, CP_UTF8);
tmem.Read(_res, textbuf.mLength);
tmem.Close();

char dbg[256];
sprintf(dbg, "mBuffer is %X, _res is %X", textbuf.mBuffer, _res);
MessageBox(NULL, dbg, "debug", MB_OK);

for (size_t i = 0; i < strlen(_res); i++)
    _res[i] ^= 168;

sprintf(dbg, "mBuffer is %X, _res is %X", textbuf.mBuffer, _res);
MessageBox(NULL, dbg, "debug", MB_OK);

textbuf.mBuffer = _res;
textbuf.mLength = _ind;

sprintf(dbg, "mBuffer is %X, _res is %X", textbuf.mBuffer, _res);
MessageBox(NULL, dbg, "debug", MB_OK);

tmem.Open(textbuf, TextStream::READ | TextStream::EOL_CRLF | TextStream::EOL_ORPHAN_CR, CP_UTF8);

编译器在“sprintf”中发现错误,我应该怎么做才能消除这个错误?

我使用Microsoft Visual Studio 2010

1 个答案:

答案 0 :(得分:2)

  

我使用Microsoft Visual Studio 2010

由于你的编译器,也许你应该用sprintf替换_sprintf 我没有看到任何错误。