Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How do I convert a string into a "string stream" using istrstream

78 views
Skip to first unread message

Michael A. Hansen

unread,
Apr 6, 1998, 3:00:00 AM4/6/98
to

Hi,

When I try to convert a string into a string stream (see code below) I get
the following error message:

Could not find a match for 'istrstream::istrstream
(std::basic_string<char,std::string_char_traits<char>,std::allocator<char>>)
'

1) Why is that and what syntax should I be using instead of "istrstream
inLine(s1);" ???
2) How do I configure Borland's C++ Builder to give more detailed error
messages?


Code:

#include <string>
#include <iostream.h>
#include <strstrea.h>
using namespace std;
int main() {
string s1;
cout << "Enter something: ";
getline(cin, s1, '\n');
istrstream lineIn(s1);
return 0;
}

Thanks,

Michael Hansen

PS. Using "istrstream inLine(s1.c_str());" I get the error message: Could
not find a match for 'istrstream::istrstream (const char*)'

Wilfried Cordes

unread,
Apr 9, 1998, 3:00:00 AM4/9/98
to

Michael A. Hansen schrieb in Nachricht <6gcejh$ma...@forums.borland.com>...

>Could not find a match for 'istrstream::istrstream
>(std::basic_string<char,std::string_char_traits<char>,std::allocator<char>>
)
>1) Why is that and what syntax should I be using instead of "istrstream
>inLine(s1);" ???

istrstream doesn't work on C++-"string". You have to write

istrstream lineIn( const_cast<char*>( s1.c_str() ) );

Casting away constness is necessary because istrstream expects a non-const
C-style char pointer and string::c_str() gives a const pointer.

The new C++-standard defines a "istringstream" in the header <sstream>
(says Bjarne Stroustrup). Is this available in Builder 3?
--
Wilfried Cordes
DDBST Software and Separation Technology GmbH

Patrick Bennett

unread,
Apr 9, 1998, 3:00:00 AM4/9/98
to

"Wilfried Cordes" <cor...@ddbst.de> wrote:

>The new C++-standard defines a "istringstream" in the header <sstream>
>(says Bjarne Stroustrup). Is this available in Builder 3?

Yes, it's available - an 'include <sstream>' will bring it in.
-------------------------------------------
Patrick Bennett
Acraline Products, Inc.
pben...@acraline.com

Michael A. Hansen

unread,
Apr 14, 1998, 3:00:00 AM4/14/98
to

I'm not sure that #include <sstream> is available in Builder 3. I have no
sstream.h in my include directory and the compiler will not recognize
#include <sstream>.


Mike Hansen

Patrick Bennett

unread,
Apr 14, 1998, 3:00:00 AM4/14/98
to

I have sstream.cc and sstream.h in my cbuilder3\include directory. If it
belches on #include <sstream>, then your include directory isn't set
correctly.

0 new messages