ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

C++ - Opening a printer file using std::ofstream

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • C++ - Opening a printer file using std::ofstream

    Can anyone help me understand how to open a printer file in C++ using an ofstream or if it is not possible? I've tried each of the following without success:

    Code:
    std::ofstream stream("QSYSPRT");    // Makes a new text file named QSYSPRT in /home/<user>
    std::ofstream stream("QSYSPRT   *LIBL     ");    // Makes a new text file named "QSYSPRT   *LIBL     " in /home/<user>
    std::ofstream stream("*LIBL/QSYSPRT");    // Open fails
    std::ofstream stream("/QSYS.LIB/QSYSPRT.FILE");    // Open fails
    std::ofstream stream("/QSYS.LIB/QSYSPRT.FILE/QSYSPRT.MBR");    // Open fails

  • #2
    I'm not familiar with 'ofstream'.

    Here's a section of the ILE C/C++ manual that describes using printer files:


    Personally, I prefer to use externally defined printer files with _Ropen() and related functions.

    Comment


    • #3
      Thank you very much for checking on it. I read the same, and I've been able to work with printer files using stdio.h and recio.h library functions. The specific problem I'm encountering here is trying to write a class that can register and report to ostream and derived classes:

      Code:
      class MyClass {
      public:
          void Register(std::ostream* stream);
          void Unregister(std::ostream* stream);
      private:
          std::vector<std::ostream*> streams;
          void Notify(const std::string& message)
          {
              for ( auto it : streams )
              {
                  (*it) << message << std::endl;
              }
          }
      };
      With this design, the only ways I'm aware of to achieve output to QSYSPRT would be either figure out how to get ofstream to work, write a custom class that that inherits from ostream which I'm loathe to do, or use some sort of intermediate stream to capture the output and then move it QSYSPRT which is cumbersome.

      Maybe I'll have to do something alternative, but it seemed more likely I'm doing something wrong and less likely that stdio.h functions would work while fstream classes wouldn't.

      Comment

      Working...
      X