|
Boost : |
From: Gregory Colvin (gregory.colvin_at_[hidden])
Date: 2003-05-03 22:43:31
On Saturday, May 3, 2003, at 21:12 America/Denver, Justin M. Lewis
wrote:
> ...
> A little bit of an overly simple example. How about something more
> like
>
> void MyGetCWD(c_out<std::string> cwd)
> {
> char *buf = new char[FIRSTSIZE];
> unsigned int size = FIRSTSIZE;
> while(getcwd(buf, sizeof(buf)) == NULL)
> {
> delete [] buf;
> size += step;
> buf = new char[size];
> }
>
> cwd = buf;
> delete[] buf;
> }
Why not this?
std::string GetCWD() {
size_t size = FIRSTSIZE;
boost::scoped_array<char> buf(new char[size]);
while (!getcwd(buf,size))
buf.reset(new char[size *= 2]);
return std::string(buf);
}
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk