473,387 Members | 1,925 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Queries about strstream.h

hello to all,
#include<iostream.h>
#include<conio.h>
#include <strstream.h>
void main()
{
clrscr();
strstream str;
char *a = new char[50];
int i;
cin >> i;
ostrstream s;
s<<"\nvalue of i is "<<i<<ends;
cout<<"\nIn s we have"<<s.str();

str<<i<<ends;
cout<<"\nusing rdbuf "<<str.rdbuf();

getch();
}

correct me if i am wrong.
Is Strstream is just used for converting interger and formatting it into strings.

what is the difference between "s.str()" and "str.rdbuf()" ?
the output is the same.

Did strstream have anyother functions.
I checked c++ library , but i cannot understand a word.
thankyou in advance,
vishnu
Jul 22 '05 #1
6 2833
vishnu mahendra wrote:

Your textbook is due for recycling. Please don't sell it on.
#include<iostream.h>
Wrong. The standard C++ header you want is called 'iostream',
without the ".h".
#include<conio.h>
Wrong. There is no standard C++ header corresponding to this one.
#include <strstream.h>
Wrong. This header and everything it provides is deprecated.
You should use the 'sstream' header and the 'stringstream'
class template instead.
void main()
Wrong. The main function always returns int.
{
clrscr();
Wrong. There is no way to clear the console's screen in standard C++.
strstream str;
Should be "std::stringstream str;", but why bother, if you're not going
to use it?
char *a = new char[50];
(i). You never delete [] the memory allocated here. That's bad.
(ii). You never use the variable a at all, so don't declare it.
(iii). Why 50?

Use std::string for strings.
int i;
cin >> i;
Should be "std::cin >> i;".

ostrstream s;
Should be "std::ostringstream s;"
s<<"\nvalue of i is "<<i<<ends;
You don't need the "ends" with std::stringstream,
since std::string doesn't need to be null-terminated.
cout<<"\nIn s we have"<<s.str();
OK, but qualify "cout" with "std::".
str<<i<<ends;
What was that for?
cout<<"\nusing rdbuf "<<str.rdbuf();
I daresay you don't need to know about std::basic_ios <>::rdbuf () yet.
getch();
Wrong. There is no way to wait for a single keypress in standard C++. }

correct me if i am wrong.
Is Strstream is just used for converting interger and formatting it into strings.
You shouldn't be using it at all. stringstream, on the other hand, is
used for converting any built-in type into a string. It also works with
user-defined types if you provide the right overloaded << operator.
what is the difference between "s.str()" and "str.rdbuf()" ?
the output is the same.
std::stringstream::str () returns the string you want. std::basic_ios
<>::rdbuf () returns a pointer to the streambuf used by the stream
object on which it is called. The << operator is overloaded in the
basic_ostream class to allow the insertion of a streambuf into an output
stream. This is mostly of interest to people implementing stream, not
users.
Did strstream have anyother functions.
std::stringstream has lots of member functions.
I checked c++ library , but i cannot understand a word.
Get a better book. I recommend "The C++ Programming Language",
3rd/Special edition, by Bjarne Stroustrup, for starters.
thankyou in advance,
vishnu


--
Regards,
Buster.
Jul 22 '05 #2
vishnu mahendra wrote:

Your textbook is due for recycling. Please don't sell it on.
#include<iostream.h>
Wrong. The standard C++ header you want is called 'iostream',
without the ".h".
#include<conio.h>
Wrong. There is no standard C++ header corresponding to this one.
#include <strstream.h>
Wrong. This header and everything it provides is deprecated.
You should use the 'sstream' header and the 'stringstream'
class template instead.
void main()
Wrong. The main function always returns int.
{
clrscr();
Wrong. There is no way to clear the console's screen in standard C++.
strstream str;
Should be "std::stringstream str;", but why bother, if you're not going
to use it?
char *a = new char[50];
(i). You never delete [] the memory allocated here. That's bad.
(ii). You never use the variable a at all, so don't declare it.
(iii). Why 50?

Use std::string for strings.
int i;
cin >> i;
Should be "std::cin >> i;".

ostrstream s;
Should be "std::ostringstream s;"
s<<"\nvalue of i is "<<i<<ends;
You don't need the "ends" with std::stringstream,
since std::string doesn't need to be null-terminated.
cout<<"\nIn s we have"<<s.str();
OK, but qualify "cout" with "std::".
str<<i<<ends;
What was that for?
cout<<"\nusing rdbuf "<<str.rdbuf();
I daresay you don't need to know about std::basic_ios <>::rdbuf () yet.
getch();
Wrong. There is no way to wait for a single keypress in standard C++. }

correct me if i am wrong.
Is Strstream is just used for converting interger and formatting it into strings.
You shouldn't be using it at all. stringstream, on the other hand, is
used for converting any built-in type into a string. It also works with
user-defined types if you provide the right overloaded << operator.
what is the difference between "s.str()" and "str.rdbuf()" ?
the output is the same.
std::stringstream::str () returns the string you want. std::basic_ios
<>::rdbuf () returns a pointer to the streambuf used by the stream
object on which it is called. The << operator is overloaded in the
basic_ostream class to allow the insertion of a streambuf into an output
stream. This is mostly of interest to people implementing stream, not
users.
Did strstream have anyother functions.
std::stringstream has lots of member functions.
I checked c++ library , but i cannot understand a word.
Get a better book. I recommend "The C++ Programming Language",
3rd/Special edition, by Bjarne Stroustrup, for starters.
thankyou in advance,
vishnu


--
Regards,
Buster.
Jul 22 '05 #3
Hello sir,

Thank you for the help. your help is much appreciated.
By the way i forgot to tell you that i am using Turbo C++.
i am a newbie so i made lots of mistakes.

thankyou again,
vishnu
Jul 22 '05 #4
Hello sir,

Thank you for the help. your help is much appreciated.
By the way i forgot to tell you that i am using Turbo C++.
i am a newbie so i made lots of mistakes.

thankyou again,
vishnu
Jul 22 '05 #5
vishnu mahendra wrote:
Thank you for the help. your help is much appreciated.
By the way i forgot to tell you that i am using Turbo C++.
i am a newbie so i made lots of mistakes.


I'm glad you found it helpful. Sorry if I was rude.

--
Regards,
Buster.
Jul 22 '05 #6
vishnu mahendra wrote:
Thank you for the help. your help is much appreciated.
By the way i forgot to tell you that i am using Turbo C++.
i am a newbie so i made lots of mistakes.


I'm glad you found it helpful. Sorry if I was rude.

--
Regards,
Buster.
Jul 22 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Bpb | last post by:
I'm trying to use a string stored in a strstream object as the filename parameter in the open call on an fstream object.. It requires a const char* but no matter what I try I can't seem to get a...
4
by: vishnu mahendra | last post by:
Can anyone please tell me what is the use of "strstream.h" header file and the functions in "strstream.h". where can i find documentation for that header file. thankyou in advance, vishnu.
6
by: vishnu mahendra | last post by:
hello to all, #include<iostream.h> #include<conio.h> #include <strstream.h> void main() { clrscr(); strstream str; char *a = new char; int i;
2
by: derek | last post by:
Hi, I'm trying to compile someone's code which uses ostrstream. I know it's declared in file strstream, but I can't find this file in the /usr/include/c++/3.3.3 directory. There is a file called...
2
by: b83503104 | last post by:
Hi, An old code is using stuff like #include <strstream.h> ostrstream *m_actionStream; and the compiler complained syntax error before `*' token I followed some previous posts and tried...
10
by: Aaron Gray | last post by:
Hi, I have an application that uses 'strstream' in just under half its .cc files, about 10 files. What is the replacement for 'strstream' ? What are my options for replacing it ? Many...
8
by: berkay | last post by:
hi all,i need this header file can anyone send it.thanks all.
5
by: nithya4u | last post by:
I am working on a c++ module, where large amount of data needs to be written to a stream and str() method is been used to assign the value of this to the char*. This produces the intended result....
4
by: morten44 | last post by:
here the output and my Compiler version, It is a basic example from Bjarne Stroustrups homepage, morten@Westparkstr42:~/Bjarne_Stroustrup/06_Chapter_06$ g++ dc_except.c...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.