Use CString with sprintf
I have a C ++ code where I need to use CString with sprintf. In this code, I create CStrings file names that are defined by sprintf. The code is below.
double Number;
Number = 0.25;
char buffer [50];
CString sFile;
sFile = sprintf(buffer,"TRJFPICD(%3.3f).txt",Number);
CString SFFile;
SFFile = sprintf(buffer,"TRJFPICV(%3.3f).txt",Number);
CString SFFFile;
SFFFile = sprintf(buffer,"TRJFPICA(%3.3f).txt",Number);
Required file names: TRJFPICD(0.25).txt, TRJFPICV(0.25).txt
and TRJFPICA(0.25).txt
. I need to use CStrings for my code.
The error I am getting is " operator =
" is ambiguous.
source to share
Take a look CString::Format
(ignore the part CStringT
- CString
derived from CStringT
). It does what you want and allows you to completely rewrite your code:
double Number = 0.25;
CString sFile;
sFile.Format(_T("TRJFPICD(%3.3f).txt"), Number);
CString SFFile;
SFFile.Format(_T("TRJFPICV(%3.3f).txt"),Number);
CString SFFFile;
SFFFile.Format(_T("TRJFPICA(%3.3f).txt"),Number);
source to share