linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Joseph D. Wagner" <wagnerjd@prodigy.net>
To: linux-c-programming@vger.kernel.org
Cc: redhat-devel-list@redhat.com, kb9mnx@fourway.net
Subject: IntToChar now NumberToString
Date: Mon, 30 Dec 2002 18:10:36 -0600	[thread overview]
Message-ID: <001201c2b061$0c46ad70$0d75d73f@joe> (raw)

[-- Attachment #1: Type: text/plain, Size: 534 bytes --]

Special thanks to J. Apple Muncy [kb9mnx@fourway.net] I was able to reduce
my original code from 60 lines to 3 lines.  (Oh, my original code was
pathetic, wasn't it?)

This new and improved template function will convert any number of any kind
(signed, unsigned, int, double, short, long, float, etc.) to its string
equivalent.

For example:

int myInt = 923746;

becomes

string myString("923746");

This isn't exactly how it works but I wrote that little bit just to complete
your mental picture.

Joseph Wagner

[-- Attachment #2: NumberToString.hpp --]
[-- Type: text/plain, Size: 1308 bytes --]

// Template Function: NumberToString

// Copyright © 2002 Joseph Wagner.  All rights reserved.
// Email: wagnerjd@users.sourceforge.net
// 
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
// 
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
// 
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

#pragma once

#include <sstream>
using std::ostringstream;

template<typename NumberType>
const string NumberToString(const NumberType number) {
	// Declares variable used as a medium in conversion
	ostringstream numberStream;

	// Converts number into output string stream
	numberStream << number;

	// Converts output string stream to string, and returns a copy
	return numberStream.str();
}

                 reply	other threads:[~2002-12-31  0:10 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='001201c2b061$0c46ad70$0d75d73f@joe' \
    --to=wagnerjd@prodigy.net \
    --cc=kb9mnx@fourway.net \
    --cc=linux-c-programming@vger.kernel.org \
    --cc=redhat-devel-list@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).