www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/07/04/08:00:58

From: Laurence Withers <lwithers AT lwithers DOT demon DOT co DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Formatting Strings?
Date: Sat, 4 Jul 1998 12:08:41 +0100
Organization: Integrated Peripherals
Message-ID: <DQ$dUBA50gn1EwU4@lwithers.demon.co.uk>
NNTP-Posting-Host: lwithers.demon.co.uk
MIME-Version: 1.0
Lines: 31
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Hi,

For my game, I would like to format strings. I know how to do this in C,
using varargs and vstrnfmt, etc, but I'm writing the game in C++. I'm
trying to use the "strstream" class which seems to do what I want, but
there are problems reading the string back.

Basically, the strstream class is similar to other stream classes in
that you can use insertors and extractors. Then you use the function

  char *str();

to read the string you have created. However, the string doesn't seem to
be null terminated, and I don't want to write  string << [...] << '\0';
all the time. Also, I can't find how to erase the string.

So, my question:

1. Has anybody any advice for using the strstream class? It seems to do    
   what I want but I can't get it to work.

2. Is there any other way to create formatted strings? My game uses a 
   lot of text (it's a Roguelike) which changes a lot, so formatting 
   strings is important. I like the look of the strstream class because
   you can use the C++ insertors without worrying about %d and %f 
   symbols...

Thanks very much for your help, and bye for now,
-- 
Laurence Withers, mailto:lwithers AT lwithers DOT demon DOT co DOT uk
OPES homepage:   http://www.lwithers.demon.co.uk/opes/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019