what is the difference between string.h and cstring?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Xiaoshen Li

    what is the difference between string.h and cstring?

    Dear All,

    I saw some people using
    #include <string.h>

    some people using
    #include <cstring>

    What is the difference between the two? I can find the file string.h at
    /usr/include. I don't know if cstring is a file and if so, where to find it.

    It seems that there are also other similar things, like:
    #include <math.h>

    #include <cmath> (?? I am not really sure.)

    Thank you very much.

  • Keith Thompson

    #2
    Re: what is the difference between string.h and cstring?

    Xiaoshen Li <xli6@gmu.edu > writes:[color=blue]
    > I saw some people using
    > #include <string.h>
    >
    > some people using
    > #include <cstring>
    >
    > What is the difference between the two? I can find the file string.h
    > at /usr/include. I don't know if cstring is a file and if so, where to
    > find it.[/color]

    <string.h> is C; <cstring> is C++.

    I *think* both forms are legal in C++, but I don't know the details;
    try comp.lang.c++ (but check their FAQ first).

    --
    Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.

    Comment

    • Martin Ambuhl

      #3
      Re: what is the difference between string.h and cstring?

      Xiaoshen Li wrote:[color=blue]
      > Dear All,
      >
      > I saw some people using
      > #include <string.h>[/color]

      This is the standard C header.
      [color=blue]
      > some people using
      > #include <cstring>[/color]

      This is a C++ header and has no defined meaning in C.[color=blue]
      >
      > What is the difference between the two?[/color]

      See above.

      Comment

      • Lew Pitcher

        #4
        Re: what is the difference between string.h and cstring?

        -----BEGIN PGP SIGNED MESSAGE-----
        Hash: SHA1

        Xiaoshen Li wrote:[color=blue]
        > Dear All,
        >
        > I saw some people using
        > #include <string.h>[/color]

        Then, they were probably writing programs in the C programming language
        [color=blue]
        > some people using
        > #include <cstring>[/color]

        And, these people were probably writing programs in the C++ programming language.
        [color=blue]
        > What is the difference between the two?[/color]

        One (string.h) is an include file for C, and is on-topic in comp.lang.c

        The other (cstring) presumably is an analogous file for C++, and is off-topic in
        comp.lang.c



        - --
        Lew Pitcher
        IT Specialist, Enterprise Data Systems,
        Enterprise Technology Solutions, TD Bank Financial Group

        (Opinions expressed are my own, not my employers')
        -----BEGIN PGP SIGNATURE-----
        Version: GnuPG v1.2.4 (MingW32)

        iD8DBQFDoxiiagV FX4UWr64RAszWAK DmKo3/8RFyXnRalyld569 yeCkbKACgzU0A
        p1ZmpiSpXfB7KgF 0ae1qzPI=
        =w28L
        -----END PGP SIGNATURE-----

        Comment

        • Dominik Wallner

          #5
          Re: what is the difference between string.h and cstring?

          Xiaoshen Li wrote:[color=blue]
          > Dear All,
          >
          > I saw some people using
          > #include <string.h>
          >
          > some people using
          > #include <cstring>
          >
          > What is the difference between the two? I can find the file string.h at
          > /usr/include. I don't know if cstring is a file and if so, where to find
          > it.
          >
          > It seems that there are also other similar things, like:
          > #include <math.h>
          >
          > #include <cmath> (?? I am not really sure.)
          >
          > Thank you very much.
          >[/color]

          Yes, <xxx.h> is the C header (which also works for C++, though), and
          <cxxx> is the corresponding C++ header file; the difference between
          those both is that all the definitions of <cxxx> are in the C++
          namespace std (like the STL), whereas <xxx.h> defines no namespace at all.

          Regards,
          Dominik Wallner

          Comment

          • Default User

            #6
            Re: what is the difference between string.h and cstring?

            Keith Thompson wrote:

            [color=blue]
            > <string.h> is C; <cstring> is C++.
            >
            > I think both forms are legal in C++, but I don't know the details;
            > try comp.lang.c++ (but check their FAQ first).[/color]

            <OT>

            <string.h> is standard but deprecated in C++.

            </OT>



            Brian

            Comment

            • Michael Mair

              #7
              Re: what is the difference between string.h and cstring?

              Dominik Wallner wrote:[color=blue]
              > Xiaoshen Li wrote:
              >[color=green]
              >> Dear All,
              >>
              >> I saw some people using
              >> #include <string.h>
              >>
              >> some people using
              >> #include <cstring>
              >>
              >> What is the difference between the two? I can find the file string.h
              >> at /usr/include. I don't know if cstring is a file and if so, where to
              >> find it.
              >>
              >> It seems that there are also other similar things, like:
              >> #include <math.h>
              >>
              >> #include <cmath> (?? I am not really sure.)[/color]
              >
              > Yes, <xxx.h> is the C header (which also works for C++, though), and
              > <cxxx> is the corresponding C++ header file; the difference between
              > those both is that all the definitions of <cxxx> are in the C++
              > namespace std (like the STL), whereas <xxx.h> defines no namespace at all.[/color]

              Please stay on topic; if you give off-topic information, there
              may be no one to correct potential errors. In this case, you omitted
              that <xxx.h> is deprecated since the 1998 C++ standard -- this may be
              helpful for the OP when deciding which variant to use in C++.
              Rather direct off-topic requests to the appropriate newsgroup.


              Cheers
              Michael
              --
              E-Mail: Mine is an /at/ gmx /dot/ de address.

              Comment

              Working...