iostream issue [modified]
-
I have committed this(ese) mistake several times. There are 2 problems with the code below.
void Connect(LPCTSTR szServer, LPCTSTR szUser, LPCTSTR szPassword)
{
std::stringstream ss;
ss << "Server = " << szServer
<< "User = " << szUser
<< "; Password = " << szPassword;Ext_ConnectToDatabase(ss.str().c_str());
}//Some external library has following sig
void Ext_ConnectToDatabase(const char* szConnectString);-- modified at 9:59 Thursday 28th September, 2006
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -Brian Kernighan
-
I have committed this(ese) mistake several times. There are 2 problems with the code below.
void Connect(LPCTSTR szServer, LPCTSTR szUser, LPCTSTR szPassword)
{
std::stringstream ss;
ss << "Server = " << szServer
<< "User = " << szUser
<< "; Password = " << szPassword;Ext_ConnectToDatabase(ss.str().c_str());
}//Some external library has following sig
void Ext_ConnectToDatabase(const char* szConnectString);-- modified at 9:59 Thursday 28th September, 2006
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -Brian Kernighan
One little bu should be the missing semicolon in the result stream between szServer und "User". c_str() returns a const char*. Maybe the external lib want modify the char* getting through parameter ?
\\\\\\|/// \\\\ - - // ( @ @ )
+---------------oOOo-(_)-oOOo-----------------+
| Stephan Pilz stephan.pilz@stephan-pilz.de |
| www.stephan-pilz.de |
| ICQ#: 127823481 |
+-----------------------Oooo------------------+
oooO ( )
( ) ) /
\ ( (_/
\_) -
I have committed this(ese) mistake several times. There are 2 problems with the code below.
void Connect(LPCTSTR szServer, LPCTSTR szUser, LPCTSTR szPassword)
{
std::stringstream ss;
ss << "Server = " << szServer
<< "User = " << szUser
<< "; Password = " << szPassword;Ext_ConnectToDatabase(ss.str().c_str());
}//Some external library has following sig
void Ext_ConnectToDatabase(const char* szConnectString);-- modified at 9:59 Thursday 28th September, 2006
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -Brian Kernighan
It isn't Unicode friendly, but I don't know if that is relevant. You are using
TCHAR
friendly params toConnect
, but then you use the ASCIIstringstream
function. With a Unicode build, this isn't going to work is it? You would need to usestd::wstringstream
, or, better still, something likestd::basic_stringstream<TCHAR>
. Also, theEx_ConnectToDatabase
function takes achar*
andstd::stringstream::str().c_str()
returns aconst char*
.
Kicking squealing Gucci little piggy.
-
One little bu should be the missing semicolon in the result stream between szServer und "User". c_str() returns a const char*. Maybe the external lib want modify the char* getting through parameter ?
\\\\\\|/// \\\\ - - // ( @ @ )
+---------------oOOo-(_)-oOOo-----------------+
| Stephan Pilz stephan.pilz@stephan-pilz.de |
| www.stephan-pilz.de |
| ICQ#: 127823481 |
+-----------------------Oooo------------------+
oooO ( )
( ) ) /
\ ( (_/
\_)Stephan Pilz wrote:
c_str() returns a const char*.
Sorry for the typo, it is not a compilation issue. I corrected the call to external lib. The external lib accepts const char*.
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -Brian Kernighan
-
It isn't Unicode friendly, but I don't know if that is relevant. You are using
TCHAR
friendly params toConnect
, but then you use the ASCIIstringstream
function. With a Unicode build, this isn't going to work is it? You would need to usestd::wstringstream
, or, better still, something likestd::basic_stringstream<TCHAR>
. Also, theEx_ConnectToDatabase
function takes achar*
andstd::stringstream::str().c_str()
returns aconst char*
.
Kicking squealing Gucci little piggy.
Rob Caldecott wrote:
With a Unicode build, this isn't going to work is it?
That's the issue. With UNICODE build ss << szServer writes the pointer value to the stream. The compilation always succeeds. To solve that I had to add overload the operator << for streams for wchar_t.
Rob Caldecott wrote:
Also, the Ex_ConnectToDatabase function takes a char* and std::stringstream::str().c_str() returns a const char*.
That was a typo.:-O
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -Brian Kernighan
-
Rob Caldecott wrote:
With a Unicode build, this isn't going to work is it?
That's the issue. With UNICODE build ss << szServer writes the pointer value to the stream. The compilation always succeeds. To solve that I had to add overload the operator << for streams for wchar_t.
Rob Caldecott wrote:
Also, the Ex_ConnectToDatabase function takes a char* and std::stringstream::str().c_str() returns a const char*.
That was a typo.:-O
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -Brian Kernighan
You could always force the input for the connect function to be const char*'s instead of const TCHAR*'s. Of course, that only pushes it back a level, but then at least it is more clear.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac