istrstream class to be replaced

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

    istrstream class to be replaced

    Hi All,

    I have this piece of code:

    char str[500];
    ......
    double x;
    istrstream in(str);

    in >> x;
    .....
    }

    I want to replace istrstream class with another class that do the same job
    as I compile with new Solaris Compiler which doesn't has this class??
    Could I??

    B.R.
    Ahmed Ossman


  • Rolf Magnus

    #2
    Re: istrstream class to be replaced

    Ahmed Ossman wrote:
    [color=blue]
    > Hi All,
    >
    > I have this piece of code:
    >
    > char str[500];
    > .....
    > double x;
    > istrstream in(str);
    >
    > in >> x;
    > ....
    > }
    >
    > I want to replace istrstream class with another class that do the same
    > job as I compile with new Solaris Compiler which doesn't has this
    > class?? Could I??[/color]

    #include <sstream>

    double x;
    std::istringstr eam in;

    in >> x;

    }

    Comment

    • tom_usenet

      #3
      Re: istrstream class to be replaced

      On Thu, 6 Nov 2003 11:44:11 +0200, "Ahmed Ossman"
      <ahmed_ossman@m entor.com> wrote:
      [color=blue]
      >Hi All,
      >
      >I have this piece of code:
      >
      >char str[500];
      >.....
      >double x;
      >istrstream in(str);
      >
      >in >> x;
      >....
      >}
      >
      >I want to replace istrstream class with another class that do the same job
      >as I compile with new Solaris Compiler which doesn't has this class??[/color]

      Is it a C++ compiler? If so, it should have that class (otherwise it
      isn't a conforming compiler). This should work:

      #include <strstream>

      int main()
      {
      char const* str = "1.57";
      std::istrstream in(str);

      double x;
      in >> x;
      }

      Does it?
      According to

      it probably should. How about with -library=stlport 4?

      Tom

      Comment

      • Unforgiven

        #4
        Re: istrstream class to be replaced

        tom_usenet wrote:[color=blue]
        > Is it a C++ compiler? If so, it should have that class (otherwise it
        > isn't a conforming compiler). This should work:[/color]

        You're wrong. <strstream> is deprecated in most compilers, and it's fully
        standards-compliant equivalent is <sstream>. The difference is that the
        strstream classes from <strstream> were built on a char* (C-style string),
        and the stringstream classes from <sstream> are built on std::string. Their
        public interface is practically the same though.

        --
        Unforgiven

        "You can't rightfully be a scientist if you mind people thinking
        you're a fool."


        Comment

        • Ron Natalie

          #5
          Re: istrstream class to be replaced


          "Unforgiven " <jaapd3000@hotm ail.com> wrote in message news:bodv7l$1d5 9l1$1@ID-136341.news.uni-berlin.de...[color=blue]
          > tom_usenet wrote:[color=green]
          > > Is it a C++ compiler? If so, it should have that class (otherwise it
          > > isn't a conforming compiler). This should work:[/color]
          >
          > You're wrong. <strstream> is deprecated in most compilers,[/color]

          No he's right. strwstream is deprecated in the standard, but that doesn't
          mean anything. Compliers are required to implement all the language
          features expressed in the standards, even the ones marked deprecated.
          [color=blue]
          > and it's fully standards-compliant equivalent is <sstream>.[/color]

          strstream is FULLY standards compliant.
          [color=blue]
          > Their public interface is practically the same though.[/color]

          Their public interface isn't the same at all with the exception of their
          common inheritance of the iostream classes.


          Comment

          • tom_usenet

            #6
            Re: istrstream class to be replaced

            On Thu, 6 Nov 2003 18:08:58 +0100, "Unforgiven "
            <jaapd3000@hotm ail.com> wrote:
            [color=blue]
            >tom_usenet wrote:[color=green]
            >> Is it a C++ compiler? If so, it should have that class (otherwise it
            >> isn't a conforming compiler). This should work:[/color]
            >
            >You're wrong. <strstream> is deprecated in most compilers, and it's fully
            >standards-compliant equivalent is <sstream>.[/color]

            I don't understand what you mean by "<strstream > is deprecated in most
            compilers", since compilers aren't responsible for deprecation, the
            standard is.

            <strstream> is part of the C++ standard, deprecated or not. If a
            compiler doesn't have it, it isn't standards compliant. Deprecated
            means:
            "Normative for the current edition of the standard, but not guaranteed
            to be part of the Standard for future revisions."

            The difference is that the[color=blue]
            >strstream classes from <strstream> were built on a char* (C-style string),
            >and the stringstream classes from <sstream> are built on std::string. Their
            >public interface is practically the same though.[/color]

            The whole freeze thing being the main difference. strstream can be a
            lot more efficient than stringstream under some circumstances though -
            I've used it in the past for that reason when interfacing with C char*
            based APIs like POSIX mqueues, etc.

            Tom

            Comment

            • Unforgiven

              #7
              Re: istrstream class to be replaced

              Ron Natalie wrote:[color=blue]
              > "Unforgiven " <jaapd3000@hotm ail.com> wrote in message
              > news:bodv7l$1d5 9l1$1@ID-136341.news.uni-berlin.de...[color=green]
              >> tom_usenet wrote:[color=darkred]
              >>> Is it a C++ compiler? If so, it should have that class (otherwise it
              >>> isn't a conforming compiler). This should work:[/color]
              >>
              >> You're wrong. <strstream> is deprecated in most compilers,[/color]
              >
              > No he's right. strwstream is deprecated in the standard, but that
              > doesn't
              > mean anything.[/color]

              You're both right of course, I should really do my homework before
              posting... :(

              My apologies.

              --
              Unforgiven

              "You can't rightfully be a scientist if you mind people thinking
              you're a fool."


              Comment

              Working...