setw and setfill
From: Paul F. Johnson (paul_at_all-the-johnsons.co.uk)
Date: 02/29/04
- Next message: B. v Ingen Schenau: "Re: scanf returns EOF after reading non-number"
- Previous message: Francis Glassborow: "Re: When to introduce exception safety"
- Next in thread: Leor Zolman: "Re: setw and setfill"
- Reply: Leor Zolman: "Re: setw and setfill"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 29 Feb 2004 16:24:55 GMT
Hi,
I'm trying to replace some inefficient code with some nice new code, but
have hit a problem.
Basically, I'm trying to construct a std::string so that I can have
output such as #01020344.
The code I have at the moment won't work, but it is as follows
std::string tmp;
tmp << setw(2) << setfill('0') << val1 << setw(2) << setfill('0') << val2
... etc
I can replace tmp with an overloaded ostream via (in the header)
friend ostream &overload(const ostream &o, const int *v);
and in the code
ostream classname::&overload(const ostream &o, const int *v)
{
size_t vsize = sizeof(v) / sizeof(*v); // I think!
for (int i = 0; i < vsize; ++i)
o << setw(2) << setfill('0') << v[i];
return 0;
}
but I'm unsure what I'd have to assign it to a std::string.
Am I doing this the right way and how do I assign it to a std::string?
TTFN
Paul
-- One OS to fool them all One browser to find them One email client to bring them all And through security holes, blind them...
- Next message: B. v Ingen Schenau: "Re: scanf returns EOF after reading non-number"
- Previous message: Francis Glassborow: "Re: When to introduce exception safety"
- Next in thread: Leor Zolman: "Re: setw and setfill"
- Reply: Leor Zolman: "Re: setw and setfill"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|