Re: vsprintf in std
Jack wrote:
"Jack" <jl@knight.com> ???g???l???s?D:ui47luxtHHA.3688@TK2MSFTNGP03.phx.gbl...
"Jack" <jl@knight.com> ???g???l???s?D:OCdbfXvtHHA.4424@TK2MSFTNGP04.phx.gbl...
Hello,
I have been searching in help but I found that was hard to search.
What I looking for was the std counterpart of CRT vsprintf. :)
I did find something like std::vsprintf in help, but still not sure about
how to use it
original code with CRT,
vsprintf (strTab->str[strTab->numLines], format, args);
Any help is greatly appreciated
Thanks
Jack
I devised a new way :)
void appendStrTab (strTable *strTab, char *format, ...)
{
va_list args;
char o[100];
va_start (args, format); // Jack unmanaged
strTab->str.append("\n");
vsprintf ((char *)o , format, args);
strTab->str.append(o);
strTab->numLines++;
va_end(args);
}
Looks better? :)
It compiles okay.....
Thanks
Jack
I think the ultimate way is to define strTab like this.... agree?
typedef struct {
typedef struct is a C-ism - you shouldn't use it in C++ code.
dword numLines;
std::vector<std:strstream> w;
} strTable;
You should probably just have:
struct strTable
{
std::vector<std:string> lines;
};
But how do I access say the first element of the string array?
void appendStrTab (strTable *strTab, char *format, ...)
{
va_list args;
// char o[100];
va_start (args, format); // Jack unmanaged
//get the length, to prevent any possibility of buffer overrun.
int count = _vscprintf(format, args);
std::vector<char> buffer(count + 1);
// strTab->str.append("\n");
vsprintf ((char *)o[strTab->numLines].str() , format, args); // C2228
vsprintf(&buffer[0], format, args);
strTab->lines.push_back(std::string(buffer.begin(), buffer.end() - 1));
// strTab->str.append(o);
strTab->numLines++;
numLines is redundant, since it would be equal to strTab->lines.size().
va_end(args);
}
Tom