From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=0.0 required=3.0 tests=BAYES_40,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.5-pre1 X-Received: by 2002:a05:620a:15d3:: with SMTP id o19mr3376205qkm.481.1623313910731; Thu, 10 Jun 2021 01:31:50 -0700 (PDT) X-Received: by 2002:a25:cb48:: with SMTP id b69mr5928009ybg.173.1623313910487; Thu, 10 Jun 2021 01:31:50 -0700 (PDT) Path: eternal-september.org!reader02.eternal-september.org!2.eu.feeder.erje.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed9.news.xs4all.nl!feeder1.cambriumusenet.nl!feed.tweak.nl!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Thu, 10 Jun 2021 01:31:50 -0700 (PDT) In-Reply-To: <331aa8fb-271a-4a3a-b95e-d10733cbc404n@googlegroups.com> Injection-Info: google-groups.googlegroups.com; posting-host=2400:4153:6002:4a00:d35f:46fa:22b:cac5; posting-account=Mi71UQoAAACnFhXo1NVxPlurinchtkIj NNTP-Posting-Host: 2400:4153:6002:4a00:d35f:46fa:22b:cac5 References: <331aa8fb-271a-4a3a-b95e-d10733cbc404n@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <745e9171-7c45-41a7-afaf-cbe013c03196n@googlegroups.com> Subject: Re: Is it possible to redirect text output to a String or Unbounded_String? From: ytomino Injection-Date: Thu, 10 Jun 2021 08:31:50 +0000 Content-Type: text/plain; charset="UTF-8" Xref: reader02.eternal-september.org comp.lang.ada:62159 List-Id: On Thursday, June 10, 2021 at 11:17:20 AM UTC+9, Jerry wrote: > Is it possible to redirect text output to a String or Unbounded_String rather than to a file? > > I know there are versions of Put that take a string as a first argument but I don't want to have to write a special-purpose version of a stretch of code just for this purpose, since I want to keep the ability to also output text to a terminal. > > I suppose I could redirect text to a file and then somehow read it back in as one string but that seems like a kludge. > > Jerry If you are not particular about use of String or Unbounded_String, how about open_memstream(3) of libc? Import and call open_memstream to create a C-style on-memory file at first, then you can create an Ada-style File_Type from it with Ada.Text_IO.C_Streams.Open.