By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,305 Members | 1,619 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,305 IT Pros & Developers. It's quick & easy.

istrstream class to be replaced

P: n/a
Hi All,

I have this piece of code:

char str[500];
......
double x;
istrstream in(str);

in >> x;
.....
}

I want to replace istrstream class with another class that do the same job
as I compile with new Solaris Compiler which doesn't has this class??
Could I??

B.R.
Ahmed Ossman
Jul 19 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Ahmed Ossman wrote:
Hi All,

I have this piece of code:

char str[500];
.....
double x;
istrstream in(str);

in >> x;
....
}

I want to replace istrstream class with another class that do the same
job as I compile with new Solaris Compiler which doesn't has this
class?? Could I??


#include <sstream>

double x;
std::istringstream in;

in >> x;

}

Jul 19 '05 #2

P: n/a
On Thu, 6 Nov 2003 11:44:11 +0200, "Ahmed Ossman"
<ah**********@mentor.com> wrote:
Hi All,

I have this piece of code:

char str[500];
.....
double x;
istrstream in(str);

in >> x;
....
}

I want to replace istrstream class with another class that do the same job
as I compile with new Solaris Compiler which doesn't has this class??


Is it a C++ compiler? If so, it should have that class (otherwise it
isn't a conforming compiler). This should work:

#include <strstream>

int main()
{
char const* str = "1.57";
std::istrstream in(str);

double x;
in >> x;
}

Does it?
According to
http://wwws.sun.com/software/sundev/...s/cpp.html#3q0
it probably should. How about with -library=stlport4?

Tom
Jul 19 '05 #3

P: n/a
tom_usenet wrote:
Is it a C++ compiler? If so, it should have that class (otherwise it
isn't a conforming compiler). This should work:


You're wrong. <strstream> is deprecated in most compilers, and it's fully
standards-compliant equivalent is <sstream>. The difference is that the
strstream classes from <strstream> were built on a char* (C-style string),
and the stringstream classes from <sstream> are built on std::string. Their
public interface is practically the same though.

--
Unforgiven

"You can't rightfully be a scientist if you mind people thinking
you're a fool."
Jul 19 '05 #4

P: n/a

"Unforgiven" <ja*******@hotmail.com> wrote in message news:bo*************@ID-136341.news.uni-berlin.de...
tom_usenet wrote:
Is it a C++ compiler? If so, it should have that class (otherwise it
isn't a conforming compiler). This should work:
You're wrong. <strstream> is deprecated in most compilers,


No he's right. strwstream is deprecated in the standard, but that doesn't
mean anything. Compliers are required to implement all the language
features expressed in the standards, even the ones marked deprecated.
and it's fully standards-compliant equivalent is <sstream>.
strstream is FULLY standards compliant.
Their public interface is practically the same though.


Their public interface isn't the same at all with the exception of their
common inheritance of the iostream classes.
Jul 19 '05 #5

P: n/a
On Thu, 6 Nov 2003 18:08:58 +0100, "Unforgiven"
<ja*******@hotmail.com> wrote:
tom_usenet wrote:
Is it a C++ compiler? If so, it should have that class (otherwise it
isn't a conforming compiler). This should work:
You're wrong. <strstream> is deprecated in most compilers, and it's fully
standards-compliant equivalent is <sstream>.


I don't understand what you mean by "<strstream> is deprecated in most
compilers", since compilers aren't responsible for deprecation, the
standard is.

<strstream> is part of the C++ standard, deprecated or not. If a
compiler doesn't have it, it isn't standards compliant. Deprecated
means:
"Normative for the current edition of the standard, but not guaranteed
to be part of the Standard for future revisions."

The difference is that thestrstream classes from <strstream> were built on a char* (C-style string),
and the stringstream classes from <sstream> are built on std::string. Their
public interface is practically the same though.


The whole freeze thing being the main difference. strstream can be a
lot more efficient than stringstream under some circumstances though -
I've used it in the past for that reason when interfacing with C char*
based APIs like POSIX mqueues, etc.

Tom
Jul 19 '05 #6

P: n/a
Ron Natalie wrote:
"Unforgiven" <ja*******@hotmail.com> wrote in message
news:bo*************@ID-136341.news.uni-berlin.de...
tom_usenet wrote:
Is it a C++ compiler? If so, it should have that class (otherwise it
isn't a conforming compiler). This should work:


You're wrong. <strstream> is deprecated in most compilers,


No he's right. strwstream is deprecated in the standard, but that
doesn't
mean anything.


You're both right of course, I should really do my homework before
posting... :(

My apologies.

--
Unforgiven

"You can't rightfully be a scientist if you mind people thinking
you're a fool."
Jul 19 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.