#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2002
    Location
    BCN
    Posts
    84
    Rep Power
    13

    VC++ does not accept string:clear method?


    Hi,

    I'm surprised to see that Visual C++ does not accept clear as a valid method for strings. Gcc accepts it and the MSDN documentation accepts it as a method for basic_string (doesn't it mean that is also valid for string?)
    TIA
  2. #2
  3. No Profile Picture
    status unknown
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    262
    Rep Power
    11
    I'm surprised too (using Visual C++ 6.0 Enterprise Edition). But you can always use erase() instead:

    string s("Hello world");
    s.erase();
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Feb 2001
    Posts
    1,473
    Rep Power
    15
    MSDN does not list clear() as a member function of the template class basic_string. And other sources such as:

    http://cppreference.com/cppstring.html

    do not list clear() as a function of the string class.

    I went to this page in MSDN:

    string
    typedef basic_string<char> string;
    The type describes a specialization of template class basic_string for elements of type char.

    and I clicked on the link for basic_string, and I looked down the list of function definitions in the class and there is no function with the name clear()--at least with my version that's the case.
    Last edited by 7stud; August 14th, 2003 at 03:56 PM.
  6. #4
  7. No Profile Picture
    status unknown
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    262
    Rep Power
    11
    The C++ standard is a much better reference than either of those, and includes clear().

    Note that VC++ 6.0 is some way short of the C++ standard.

    cppreference.com is clearly lacking.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2002
    Location
    BCN
    Posts
    84
    Rep Power
    13
    Regarding MSDN, check this.
    http://msdn.microsoft.com/library/de...tringclear.asp
    I told I was really surprised. They document but not implement?
  10. #6
  11. No Profile Picture
    status unknown
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    262
    Rep Power
    11
    Which version of VC++ are you using? Different versions will, obviously, have different functionality.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Feb 2001
    Posts
    1,473
    Rep Power
    15
    "The C++ standard is a much better reference than either of those..."

    What, are you being coy? How about a link?
  14. #8
  15. No Profile Picture
    Offensive Member
    Devshed Novice (500 - 999 posts)

    Join Date
    Oct 2002
    Location
    in the perfect world
    Posts
    622
    Rep Power
    27
    Thats because MS wants you to use MFC CStrings and 'Empty'.
    The essence of Christianity is told us in the Garden of Eden history. The fruit that was forbidden was on the Tree of Knowledge. The subtext is, All the suffering you have is because you wanted to find out what was going on. You could be in the Garden of Eden if you had just kept your f***ing mouth shut and hadn't asked any questions.

    Frank Zappa
  16. #9
  17. No Profile Picture
    status unknown
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    262
    Rep Power
    11
    Originally posted by 7stud
    "The C++ standard is a much better reference than either of those..."

    What, are you being coy? How about a link?
    LOL, no, not being coy. As far as I know the standard isn't officially available on the internet for free. It can be bought in electronic (PDF) format for $18 from:

    http://webstore.ansi.org/AnsiDocStore/

    You may find illegal PDF copies on the internet from time to time, who knows, but for only $18 ...

    There are copies of the draft version of the standard prior to the final version floating around on the internet freely available. Although there are differences between the October 1997 draft and the final standard, the differences are actually very small. If you don't want to pay $18, the draft is good enough. Again, a search on Google will throw up some links, but I did stumble across an HTML version here:

    http://std.dkuug.dk/jtc1/sc22/wg21/docs/wp/html/oct97/

    I can't vouch for the quality of information at that site as I haven't personally used it.

    I would recommend a good C++ reference book over the standard though, for most purposes. The standard itself is very dry and requires interpretation. For the C++ language itself Stroustrup's The C++ Programming Language is very good (but not a beginner's book). For the standard library, The C++ Standard Library, A Tutorial and Reference by Jossutis is very good.

    That said, you still need to refer to your compiler documentation for implementation defined details and compiler specific extensions.


    Originally posted by TechNoFear
    Thats because MS wants you to use MFC CStrings and 'Empty'.
    Well certainly VC++ 6.0 predates the final standard and therefore doesn't claim to implement the final standard, so you will find some differences. VC++ 7 (.NET) is supposed to be far more standard compliant. I don't think there's a desire on their part to force people to use CStrings.
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Feb 2001
    Posts
    1,473
    Rep Power
    15
    Thanks.

IMN logo majestic logo threadwatch logo seochat tools logo