//###########################################################################
#include <string>
#include <strstream>
#include <iomanip.h>
template <typename T>
string SomethingToStr (T value_i, int width_i = -1, char fill_i = ' ')
{
string ret_stringValue;
strstream tmp_strstream;
//=================================
if (width_i > 0)
{
tmp_strstream.width (width_i);
tmp_strstream.fill (fill_i);
}
tmp_strstream << value_i;
//=================================
tmp_strstream << ends;
ret_stringValue = tmp_strstream.str();
tmp_strstream.rdbuf()->freeze (0);
//=================================
return ret_stringValue;
} // string SomethingToStr (T value_i)
// ######################################
Alex
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
Alex Vinokur wrote:
> In article <36F4631F...@epix.net>,
> Brian Hansell <han...@epix.net> wrote:
> > I'm hoping someone can help me with this. I'm wondering if there is a
> > command to convert an integer to a string. I think i remember a thread
> > about this being posted previously, but I'm not sure. Maybe that was
> > string to integer. Who knows, anyway, if anyone knows offhand, thanks
> > in advance.
> >
> > -Brian
> >
> >
>
> //###########################################################################
> #include <string>
> #include <strstream>
> #include <iomanip.h>
Are you aware that the use of strstream (in fact I think that should be
#include<strstream.h>)
is deprecated and may not be supported in future versions of the standard ?
Nick
Hi,
1. About strstream and strstream.h.
Here's the strstream header-file.
=======================================
// -*- C++ -*- forwarding header.
// This file is part of the GNU ANSI C++ Library.
#ifndef __STRSTREAM__
#define __STRSTREAM__
#include <strstream.h>
#endif
================================
2. What can we use instead of the strstream class now?
3. I would like to use the stringstream class,
but I got the following results :
========== main.C ================
#include <sstream>
int main ()
{
stringstream sst;
// do something
return 0;
}
==================================
====== The compilation results ===
g++ main.C
sstream: No such file or directory
==================================
P.S. Please see messages in the thread titled
"sstream: No such file or directory"
in comp.lang.c++
###########################################
Thanks,
>Are you aware that the use of strstream (in fact I think that should be
>#include<strstream.h>)
>is deprecated and may not be supported in future versions of the standard ?
Some compilers don't support stringstreams yet, so use of strstream is the
next best solution. And what was wrong with his use of the #include
<strstream> form?
--
Cheers, { The alt.comp.lang.learn.c-c++ FAQ: }
Rich. { http://www.raos.demon.co.uk/acllc-c++/faq.html }
Alex Vinokur wrote:
> In article <36F6832E...@interdyn.com>,
> Nick Ambrose <ni...@interdyn.com> wrote:
> [snip]
> >
> > Alex Vinokur wrote:
> >
>
> Hi,
>
> 1. About strstream and strstream.h.
> Here's the strstream header-file.
>
>
Buy the C++ standard ($18) from ANSI and read Annex D where the old strstream stuff
is documented ....
>
> ================================
>
> 2. What can we use instead of the strstream class now?
std::stringstream
(or: std::basic_stringstream<T> --- where T is char/wchar_t etc.)
>
>
> 3. I would like to use the stringstream class,
> but I got the following results :
>
> ========== main.C ================
> #include <sstream>
> int main ()
> {
> stringstream sst;
> // do something
> return 0;
> }
> ==================================
>
> ====== The compilation results ===
> g++ main.C
> sstream: No such file or directory
> ==================================
>
g++ doesn't do this right yet. Sorry. Look to egcs to be supporting this sometime
soon.
There is as far as I know, no free library that does this (yet) for g++
check out (http://sourceware.cygnus.com/libstdc++/) for progress.
Nick
Rich Churcher wrote:
> On Mon, 22 Mar 1999 09:51:42 -0800, Nick Ambrose <ni...@interdyn.com>
> wrote:
>
> >Are you aware that the use of strstream (in fact I think that should be
> >#include<strstream.h>)
> >is deprecated and may not be supported in future versions of the standard ?
>
> Some compilers don't support stringstreams yet, so use of strstream is the
> next best solution. And what was wrong with his use of the #include
> <strstream> form?
>
If he is using an older compiler then nothing. But strstream is deprecacted. It
won't include std::string on a new compiler (well, I guess it's not *required*
to but maybe it could)
Nick