Topic: Does the standard guarantee that the elements of string be contiguous in


Author: Anon Sricharoenchai <ans@beethoven.cpe.ku.ac.th>
Date: Mon, 19 Mar 2001 21:18:48 GMT
Raw View
Does the standard guarantee that the elements of string be contiguous in
memory after calling the method string::c_str() or string::data() ?
If not, I think it should.
This will very useful when I want to pass string as nonconst char* into
C-style function, for example,
to read data from a file descriptor in unix,

   string str; str.resize(20); str.data();
   read(fd, &str[0], str.length());

that will be more efficient than,

   string str; vector<char> buf(20);
   read(fd, &buf[0], buf.length());
   str.assign(&buf[0], buf.length());

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]