home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!psinntp!dg-rtp!webo!bhaskara.webo.dg.com!pramesh
- From: pramesh@bhaskara.webo.dg.com (Ramesh Babu)
- Subject: Re: How to limit string output length w/ stream manips?
- Sender: usenet@webo.dg.com (Usenet Administration)
- Message-ID: <1993Jan8.211251.4604@webo.dg.com>
- Date: Fri, 8 Jan 93 21:12:51 GMT
- Reply-To: pramesh@bhaskara.webo.dg.com
- References: <1993Jan8.025836.10039@news.ysu.edu> <1993Jan8.183239.10873@taumet.com>
- Organization: NSDD, Data General Corp.
- Lines: 39
-
- In article <1993Jan8.183239.10873@taumet.com>, steve@taumet.com (Steve Clamage) writes:
- |> af458@yfn.ysu.edu (Jon K. Salmon) writes:
- |>
- |>
- |> >I would like to limit the output length of a string sent to an
- |> >output stream. For example, given a string...
- |>
- |> > const char *Bob = "1234567890ABCDEF";
- |>
- |> > ... to output "12345"?
- |>
- |> As with printf(), the iostream inserters never truncate a value; output
- |> width is a minimum, not an absolute.
- |>
- |> If you want to truncate a string, you have to do the truncation yourself.
- |> --
- |>
- |> Steve Clamage, TauMetric Corp, steve@taumet.com
-
- In C printf with a format string, the above functionality can be
- implemented. Refer to pg 153 of K&R 2nd edition.
-
- Example:
-
- printf ( "%2.2s\n", "ABCD" );
-
- will output just
-
- AB
- in "%2.2" the first 2 specifies the min length and the second 2
- the max length. The first 2 can be omitted then the format string
- becomes "%.2" will have the same desired results.
-
- ***********************************************************************
- Ramesh babu P pramesh@ox.webo.dg.com
- Data General Corp.
- Westboro, Ma (508)-870-8048 Fax (508)-898-4212
- ***********************************************************************
-
-