Uploaded image for project: 'C++ Standard Library'
  1. C++ Standard Library
  2. STDCXX-1024

ill-formed iostream code code in section 34.2 of User Guide

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 4.2.1
    • 4.2.2
    • Documentation
    • None
    • Compiler Error

    Description

      As mentioned in this post, the example program in section 34.2.3 – Using Pointers or References to Streams of the User Guide is ill-formed:

      at the very end of http://stdcxx.apache.org/doc/stdlibug/34-2.html
      there is an example of using a reference to create a "copy" of cout.
      However this example doesn't initialize the defined reference at once
      (which is required in C++) and for this reason doesn't compile with my
      gcc 4.2.1.

      For convenience here is the example:

      int main(int argc, char *argv[])
      {
        std::ostream& fr;
        if (argc > 1)
          fr = *(new std::ofstream(argv[1]));
        else
          fr = std::cout;
      
        fr << "Hello world!" << std::endl;
      
        if (&fr!=&std::cout)
          delete(&fr);
      }
      

      Attachments

        Activity

          People

            sebor Martin Sebor
            sebor Martin Sebor
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - 2h
                2h
                Remaining:
                Time Spent - 1h Remaining Estimate - 1h
                1h
                Logged:
                Time Spent - 1h Remaining Estimate - 1h
                1h