strstream class

Hey guys,can anyone help me in describing what strstream classes are ?,Please reply.

I also have the following list of questions about strstreams ,try to answer them all too.

1-what is the deference between strstreams and stringstreams ?

2-why was strstream deprecated ?

3-How can I use both strstreams and stringstreams in programs ?(try to give sample programs if possible).
1 and 2 can probably be answered with the one from stackoverflow:
http://stackoverflow.com/questions/2820221/why-was-stdstrstream-deprecated

(I just googled "C++ strstream." >_>)

3) If anything is deprecated, try not to use it. Using strstream and stringstream in the same program will probably be like mixing iostream with stdio (but stdio is not deprecated FYI). Unless you are adapting older C code in a C++ program, you should probably lean more toward iostream (if you are writing a C++ program, of course).

Edit: I suppose a more correct answer is this classic example.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <stdlib.h> //<-- Note the ".h" at the end. This is a C file, not a C++ file
#include <stdio.h>//<-- Also a C and not C++ file
#include <iostream.h>//<--Nonstandard form of iostream; different compilers will have different implementations
                                   //Just showing you so you know
using namespace std;
int main(){
   char hi;
   while(true){
      cout << "Hi, press something: ";
      getch(); //Deprecated method; restricted mainly to Windows OS
      _getch(); //Have no clue how different this is, but I've seen it; it is nonstandard
      getchar();//C method for grabbing a character
      cin >> hi;//This has a rare chance of acting differently under the iostream.h header.
   }
   return 0x00BAD; //Not returning 0 because this program is all bad
}


getch() and _getch() above may or may not compile on different compilers.
iostream.h will definitely be compiled differently, so any implementations you have with its methods might not act the way you think.

Moral: Stick with standards, so your program is more flexible.
Last edited on
Sounds like homework. Aren't you supposed to research this yourself?
Topic archived. No new replies allowed.