Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual C++ "Undeclared identifier" error on sprintf only in destructor

Tags:

visual-c++

I have a program were I am trying to do some simple text logging to find an error that only manifests in release mode. I have added my logging code, and it is not flagged as an error anywhere except in the class's destructor:

CParameterMgr::~CParameterMgr ()
{
   sprintf(logData, "Deleting m_pValueBuff (Destructor)");
   TextLogger::WriteLog(logData);

   delete [] m_pValueBuff;
}

I am actually getting "error C2065: 'sprintf' : undeclared identifier"

Can anyone explain why sprintf cannot be used in a destructor?

Thanks

like image 583
Peter Howe Avatar asked Sep 02 '25 02:09

Peter Howe


1 Answers

No limitation on usage of sprintf in destructor exists. You just forgot include appropriate header file.

C-style way is

#include <stdio.h>

C++-style way is

#include <cstdio>
like image 143
Dmitry Poroh Avatar answered Sep 05 '25 01:09

Dmitry Poroh