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 6 2827
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.
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.
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
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
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.
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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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.
|
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;
|
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...
|
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...
|
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...
|
by: berkay |
last post by:
hi all,i need this header file can anyone send it.thanks all.
|
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....
|
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...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |