| delorie.com/archives/browse.cgi | search |
| From: | Martin Ambuhl <mambuhl AT earthlink DOT net> |
| Newsgroups: | comp.os.msdos.djgpp |
| Subject: | Re: Converting numbers to strings |
| Date: | Sun, 09 May 1999 10:25:27 -0400 |
| References: | <HhOCsDAf$YN3EwuI AT dunvegan1 DOT demon DOT co DOT uk> |
| X-Posted-Path-Was: | not-for-mail |
| X-Accept-Language: | en |
| X-ELN-Date: | 9 May 1999 14:24:18 GMT |
| X-ELN-Insert-Date: | Sun May 9 07:25:18 1999 |
| Organization: | Nocturnal Aviation |
| Lines: | 25 |
| Mime-Version: | 1.0 |
| NNTP-Posting-Host: | dialup-209.246.109.186.newyork2.level3.net |
| Message-ID: | <37359AD7.8FC41504@earthlink.net> |
| X-Mailer: | Mozilla 4.51 [en] (Win95; I) |
| To: | djgpp AT delorie DOT com |
| DJ-Gateway: | from newsgroup comp.os.msdos.djgpp |
| Reply-To: | djgpp AT delorie DOT com |
Paul Richards wrote:
>
> Hi,
> How do I convert numbers to strings?
>
> I need to be able to do this so that I can make up filenames:
> pic1.bmp
> pic2.bmp
> etc...
>
> In BASIC this would be string$="pic"+ltrim$(rtrim$(val(number%)))+".bmp"
> but how do I do it in C++?
This extremely ugly BASIC construction should make you appreciate the much
derided-by-C++-advocates sprintf function:
#include <cstdio>
char *filename;
int i;
sprintf(filename,"pic%d.bmp",i);
--
Martin Ambuhl (mambuhl AT earthlink DOT net)
Note: mambuhl AT tiac DOT net will soon be inactive
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |