istrstream class to be replaced

A

Ahmed Ossman

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
 
R

Rolf Magnus

Ahmed said:
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;

}
 
T

tom_usenet

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/suncc/faqs/cpp.html#3q0
it probably should. How about with -library=stlport4?

Tom
 
U

Unforgiven

tom_usenet said:
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.
 
R

Ron Natalie

Unforgiven said:
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.
 
T

tom_usenet

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 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.

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
 
U

Unforgiven

Ron said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,146
Messages
2,570,832
Members
47,374
Latest member
anuragag27

Latest Threads

Top