Prev: Visual Studio 2008 on Windows 7
Next: std::vector error
From: Alex Blekhman on 16 Dec 2009 11:54 "David Wilkinson" wrote: > In fact, I have a motto: Never use an MFC class unless you have > to. Actually, CString is not MFC class anymore. They factored it out along with other several popular classes, so now you can include CString support in your project with minimal overhead. Alex
From: Giovanni Dicanio on 16 Dec 2009 11:57 "Leigh Johnston" <leigh(a)i42.co.uk> ha scritto nel messaggio news:ePuWEnmfKHA.5228(a)TK2MSFTNGP06.phx.gbl... > You are right about the null termination being a problem, Actually, Tim Roberts enlightened me about that. Giovanni
From: David Wilkinson on 16 Dec 2009 12:34 Leigh Johnston wrote: > VC++ strings are contiguous and C++0x will guarantee contiguousness. > The current standard is ambiguous (due to an error I believe) as to > whether &s[0] is contiguous. Well, OK. But what about the length/size of the std::string s after you pass &s[0] to some API? If s.length() and strlen(s.c_str()) are not the same, things could get very confusing. -- David Wilkinson Visual C++ MVP
From: Leigh Johnston on 16 Dec 2009 13:06 > > But what about the length/size of the std::string s after you pass &s[0] > to some API? If s.length() and strlen(s.c_str()) are not the same, things > could get very confusing. > strlen(s.c_str()) and s.length() will always be the same. use std::vector<char> if you want to fill a buffer with a null terminated string or perhaps into a std::string then delete the null terminator with erase. /Leigh
From: Leigh Johnston on 16 Dec 2009 13:09
Well strlen(s.c_str()) and s.length() will not be the same if the string includes a null terminator but you are using string incorrectly if this is the case IMO. "Leigh Johnston" <leigh(a)i42.co.uk> wrote in message news:#rzBLqnfKHA.4952(a)TK2MSFTNGP06.phx.gbl... >> >> But what about the length/size of the std::string s after you pass &s[0] >> to some API? If s.length() and strlen(s.c_str()) are not the same, things >> could get very confusing. >> > > strlen(s.c_str()) and s.length() will always be the same. use > std::vector<char> if you want to fill a buffer with a null terminated > string or perhaps into a std::string then delete the null terminator with > erase. > > /Leigh |