Setting a String to NULL in C++?

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

    Setting a String to NULL in C++?

    I have a string, say GLOBAL, that I use a lot
    in a CPP-program. From time to time this string needs to
    be set to the NULL-string, i.e., empty itself of its content.
    How do we do it?
    Thanks!

    Perseus

  • Victor Bazarov

    #2
    Re: Setting a String to NULL in C++?

    "perseus" <fanta@fantigo. com> wrote...[color=blue]
    > I have a string, say GLOBAL, that I use a lot
    > in a CPP-program. From time to time this string needs to
    > be set to the NULL-string, i.e., empty itself of its content.
    > How do we do it?[/color]

    To empty a string call the 'clear' member function. There
    is no 'setting to NULL' because it's not a pointer.

    Victor


    Comment

    • perseus

      #3
      Re: Setting a String to NULL in C++?


      On Mon, 21 Jul 2003 02:14:50 GMT, "Victor Bazarov"
      <v.Abazarov@att Abi.com> wrote:
      [color=blue]
      >"perseus" <fanta@fantigo. com> wrote...[color=green]
      >> I have a string, say GLOBAL, that I use a lot
      >> in a CPP-program. From time to time this string needs to
      >> be set to the NULL-string, i.e., empty itself of its content.
      >> How do we do it?[/color]
      >
      >To empty a string call the 'clear' member function. There
      >is no 'setting to NULL' because it's not a pointer.
      >
      >Victor
      >[/color]

      Victor,

      Can I call this function in BC5 with Windows XP?
      What .h file is needed here?
      An example would be just great!
      Thanks!

      perseus

      Comment

      • Chris Johnson

        #4
        Re: Setting a String to NULL in C++?

        perseus <fanta@fantigo. com> writes:
        [color=blue]
        > Can I call this function in BC5 with Windows XP?[/color]

        Any C++ compliant compiler can do this regardless
        of platform.
        [color=blue]
        > What .h file is needed here?[/color]

        #include <string>
        [color=blue]
        > An example would be just great![/color]

        string foo("Bar need's a good C++ book");

        // examines include dir's more often

        foo.clear();

        Respectfully,
        Chris Johnson


        -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
        http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
        -----== Over 80,000 Newsgroups - 16 Different Servers! =-----

        Comment

        • Ales DOLECEK

          #5
          Re: Setting a String to NULL in C++?

          On Mon, 21 Jul 2003 07:00:58 +0100
          "John Harrison" <john_andronicu s@hotmail.com> wrote:
          [color=blue]
          >
          > "perseus" <fanta@fantigo. com> wrote in message
          > news:oanmhvgten 2ikskf9in0rpvk4 0f02faujo@4ax.c om...[color=green]
          > > Chris,
          > >
          > > It will not work on BC5.
          > >
          > > ERROR: 'clear' is not a member of
          > > std::basic_stri ng<char,std::st ring_char_trait s<char>...
          > >
          > > Thanks!
          > >
          > > perseus
          > >[/color]
          >
          > It should, but since your compiler is obviously broken, how about the
          > obvious
          >
          > foo = "";
          >
          > john[/color]

          It has nothing to do with compiler. It is unimlemented in STL you are
          using.

          BTW: I use STL from SGI on linux and have same "problem" which I solve
          in same way as John. :-)

          Ales

          Comment

          Working...