string::capacity()

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tcsvikr
    New Member
    • Feb 2007
    • 18

    #1

    string::capacity()

    Hi,
    The string::capacit y() returns the size of the allocated space, which is either equal or greater than this content size.
    My question is: Is capacity assigning equal or greater than content size compiler dependent??
    I've used the same function in a sample C++ program and compiled it with g++ compiler(linux) . The result is always equal to the content size but never greater.
    can some one help me in clarifying this.
  • gpraghuram
    Recognized Expert Top Contributor
    • Mar 2007
    • 1275

    #2
    The string functions change according to the compiler as the implementation changes compiler to compiler.

    Raghu

    Comment

    • tcsvikr
      New Member
      • Feb 2007
      • 18

      #3
      Originally posted by gpraghuram
      The string functions change according to the compiler as the implementation changes compiler to compiler.

      Raghu
      Hi Raghu!!
      Thanks for the reply.. I've observed the same in VC++ ..The implementation is different from linux

      Comment

      • Banfa
        Recognized Expert Expert
        • Feb 2006
        • 9067

        #4
        That is OK, as long as the string has enough memory for it's current contents then it is conforming to the standard.

        There are several ways to implement a conforming String class and you may well find that different platforms exhibit different behaviour. That is why it is important to learn to write code that conforms to the standard and does not rely on the special behaviour of any one platform, especially if you intend the code to compile across different platforms.

        Comment

        Working...