|
Hi Joe, Microsoft Knowledge Base Article - 326616, "BUG: Cannot Display std::string and std::wstring Variables Correctly In Visual C++ .NET Debugger", might have the answer you are looking for:
http://support.microsoft.com/default.aspx?scid=kb;en-us;326616
From that...
In the Autoexp.dat file, locate the following lines:
std::basic_string<char,std::char_traits<char>,std::allocator<char> >=<_Bx._Buf>
std::basic_string<unsigned short,std::char_traits<unsigned short>,std::allocator<unsigned short> >=<_Bx._Ptr>
std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> >=<_Bx._Ptr>
Replace with the following lines:
std::basic_string<char,std::char_traits<char>,std::allocator<char> >=
_Buf=<_Bx._Buf> _Ptr= <_Bx._Ptr>
std::basic_string<unsigned short,std::char_traits<unsigned short>,std::allocator<unsigned short> >=_Buf=<_Bx._Buf> _Ptr= <_Bx._Ptr>
std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> >=<_Bx._Buf> _Ptr= <_Bx._Ptr>
Pete
|
|
|
|
|
Will this work with VC6 too ?
|
|
|
|
|
I am using VC6 without the upgrade Joe mentioned. This is my latest version of those templates in autoexp.dat:
std::basic_string<char,std::char_traits<char>,std::allocator<char> >=<_Ptr>
std::basic_string<unsigned short,std::char_traits<unsigned short>,std::allocator<unsigned short> >=<_Ptr,su>
std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> >=<_Ptr,su>
That seems to work.
Pete
|
|
|
|
|
I finally found the solution.
I use the STLPORT library instead of the STL shipped with VC6
Here is my solution:
_STL::basic_string<*>=<_M_start>
|
|
|
|
|
like these while compiling looks like any MFC
using project:
<br />
c:\...\stdstring.h(2702) : warning C4786: '?Format@?$CStdStr@D@@QAEXIABVtemplate-parameter-CAB@ABVtemplate-parameter-CAC@ABVtemplate-parameter-CAD@ABVtemplate-parameter-CAE@ABVtemplate-parameter-CAF@ABVtemplate-paramete<br />
r-CAG@ABVtemplate-parameter-CAH@ABVtemplate-parameter-CAI@ABVtemplate-parameter-CAJ@ABVtemplate-parameter-CAK@ABVtemplate-parameter-CAL@ABVtemplate-parameter-CAM@ABVtemplate-parameter-CAN@ABVtemplate-parameter-CAO@ABVtemplate-parameter-CAP@@Z' : identifier was truncated to '255' characters in the browser information<br />
<br />
<br />
c:\mvs\vc98\include\xlocale(287) : warning C4100: '_State' : unreferenced formal parameter<br />
c:\mvs\vc98\include\xlocale(289) : while compiling class-template member function 'int __thiscall std::codecvt<char,char,int>::do_length(int &,const char *,const char *,unsigned int) const'<br />
<br />
<br />
c:\mvs\vc98\include\xlocale(289) : warning C4018: '<' : signed/unsigned mismatch<br />
c:\mvs\vc98\include\xlocale(289) : while compiling class-template member function 'int __thiscall std::codecvt<char,char,int>::do_length(int &,const char *,const char *,unsigned int) const'<br />
<br />
<br />
c:\mvs\vc98\include\xlocnum(179) : warning C4146: unary minus operator applied to unsigned type, result still unsigned<br />
c:\mvs\vc98\include\xlocnum(168) : while compiling class-template member function 'class std::istreambuf_iterator<unsigned short,struct std::char_traits<unsigned short> > __thiscall std::num_get<unsigned short,class std::istreambuf_iterator<<br />
<br />
Compiling a project that is not using MFC looks fine.
Please help!
|
|
|
|
|
Hi,
Well let's be sure you have the very latest version of the code before we panic. The version that is (or was) on CodeProject was years out of date. I've sent and updated version (yesterday) to CodeProject but I don't know if it's up yet. You can always the latest version here:
http://home.earthlink.net/~jmoleary/code/StdString.zip
Try that and see what it tells you.
-Joe
|
|
|
|
|
That's exactly what I'm using.
I didn't mention before - this is with VC 6.
I figured that the fist warning I listed will go away if I disable "Generate Browse info" in project settings. Still would be nice to have that on.
The others are still there. I get like around 1200 warnings
|
|
|
|
|
Can you send me a zipped-up VC6 project (without the .obj files or any of that) that generates all the warnings? I'll take hit home tonight and try it out (I don't have VC6 at work) and get back to you here.
I'm able to build this code with VC6 with zero warnings so I'm a little surprised you're having so much trouble. But if you can send me something, I'll figure it out.
My email address is in the StdString.h header file.
-Joe
|
|
|
|
|
E-Mailed. Thanks a lot for all the attention!
|
|
|
|
|
I've already talked to "inner" via email but just to post officially here, the warnings he listed are actually ALL caused by the VC6 implementation of the Standard C++ Library. It was a poor implementation and Dinkumware got rid of all these warnings in their next release.
In the meantime, those of you who have VC6, you'll need to #pragma the warnings away. Sorry. I didn't put the #pragmas in the StdString.h header because a) the warnings are harmless and b)I prefer to leave the choice up to the person using the code since their caused by code that's completely out of my control (Dinkumware's VC6 C++ Library).
I generally place the #pragmas in my precompiled header file.
-Joe
|
|
|
|
|
In VS 7.0 only one level 4 warning is displayed when compiling this class, with 'Detect 64 bit Portability issues' turned off. I've modified the class below to remove it:
template<typename ct="">
struct NotSpace : public std::unary_function<ct, bool="">
{
// DINKUMWARE BUG:
// Note -- using std::isspace in a COM DLL gives us access violations
// because it causes the dynamic addition of a function to be called
// when the library shuts down. Unfortunately the list is maintained
// in DLL memory but the function is in static memory. So the COM DLL
// goes away along with the function that was supposed to be called,
// and then later when the DLL CRT shuts down it unloads the list and
// tries to call the long-gone function.
// This is DinkumWare's implementation problem. If you encounter this
// problem, you may replace the calls here with good old isspace() and
// iswspace() from the CRT unless they specify SS_ANSI
const std::locale loc;
NotSpace(const std::locale& locArg=std::locale()) : loc(locArg) {}
bool operator() (CT t) const { return !std::isspace(t, loc); }
private:
// Private copy assignment resolve the C4512 warning.
const NotSpace &operator=(const NotSpace&); // Added line
};
|
|
|
|
|
It surely should be interesting and useful a CString-clone not using Microsoft C++ ...
So I test to compile Borland Builder C++, and it gives :
==========================================================
Borland C++ 5.6 for Win32 Copyright (c) 1993, 2002 Borland
.\TestString.cpp:
Error E2451 .\StdString.h 442: Undefined symbol 'mbstate_t'
Error E2451 .\StdString.h 463: Undefined symbol 'result' in function StdCodeCvt(wchar_t *,const char *,int,const _STL::locale &)
Error E2379 .\StdString.h 463: Statement missing ; in function StdCodeCvt(wchar_t *,const char *,int,const _STL::locale &)
Error E2451 .\StdString.h 465: Undefined symbol 'state_type' in function StdCodeCvt(wchar_t *,const char *,int,const _STL::locale &)
Error E2379 .\StdString.h 465: Statement missing ; in function StdCodeCvt(wchar_t *,const char *,int,const _STL::locale &)
Error E2451 .\StdString.h 466: Undefined symbol 'res' in function StdCodeCvt(wchar_t *,const char *,int,const _STL::locale &)
Error E2316 .\StdString.h 466: 'in' is not a member of 'SSCodeCvt' in function StdCodeCvt(wchar_t *,const char *,int,const _STL::locale &)
Error E2451 .\StdString.h 466: Undefined symbol 'st' in function StdCodeCvt(wchar_t *,const char *,int,const _STL::locale &)
Error E2451 .\StdString.h 469: Undefined symbol 'ok' in function StdCodeCvt(wchar_t *,const char *,int,const _STL::locale &)
Error E2451 .\StdString.h 486: Undefined symbol 'result' in function StdCodeCvt(char *,const wchar_t *,int,const _STL::locale &)
Error E2379 .\StdString.h 486: Statement missing ; in function StdCodeCvt(char *,const wchar_t *,int,const _STL::locale &)
Error E2451 .\StdString.h 488: Undefined symbol 'state_type' in function StdCodeCvt(char *,const wchar_t *,int,const _STL::locale &)
Error E2379 .\StdString.h 488: Statement missing ; in function StdCodeCvt(char *,const wchar_t *,int,const _STL::locale &)
Error E2451 .\StdString.h 489: Undefined symbol 'res' in function StdCodeCvt(char *,const wchar_t *,int,const _STL::locale &)
Error E2316 .\StdString.h 489: 'out' is not a member of 'SSCodeCvt' in function StdCodeCvt(char *,const wchar_t *,int,const _STL::locale &)
Error E2451 .\StdString.h 489: Undefined symbol 'st' in function StdCodeCvt(char *,const wchar_t *,int,const _STL::locale &)
Error E2451 .\StdString.h 492: Undefined symbol 'ok' in function StdCodeCvt(char *,const wchar_t *,int,const _STL::locale &)
Error E2034 .\StdString.h 1111: Cannot convert 'unsigned int' to 'const wchar_t *' in function ssvsprintf(wchar_t *,unsigned int,const wchar_t *,void *)
Error E2342 .\StdString.h 1111: Type mismatch in parameter '__format' (wanted 'const wchar_t *', got 'unsigned int') in function ssvsprintf(wchar_t *,unsigned int,const wchar_t *,void *)
Error E2034 .\StdString.h 1111: Cannot convert 'const wchar_t *' to 'void *' in function ssvsprintf(wchar_t *,unsigned int,const wchar_t *,void *)
Error E2342 .\StdString.h 1111: Type mismatch in parameter '__arglist' (wanted 'void *', got 'const wchar_t *') in function ssvsprintf(wchar_t *,unsigned int,const wchar_t *,void *)
Error E2227 .\StdString.h 1111: Extra parameter in call to vswprintf(wchar_t *,const wchar_t *,void *) in function ssvsprintf(wchar_t *,unsigned int,const wchar_t *,void *)
Warning W8058 C:\BORLAND\include\stlport/locale 150: Cannot create pre-compiled header: initialized data in header
Error E2268 .\TestString.cpp 15: Call to undefined function '_bstr_t' in function main(int,char * *)
Error E2268 .\TestString.cpp 26: Call to undefined function '_ASSERTE' in function main(int,char * *)
Error E2451 .\TestString.cpp 56: Undefined symbol 'SetResourceHandle' in function main(int,char * *)
Error E2228 .\TestString.cpp 56: Too many error or warning messages in function main(int,char * *)
*** 26 errors in Compile ***
==========================================================
I think there are more errors ...
How It can be handled ?
Maybe solving for GCC (g++) it could run on BBuilder.
Thanks in advance
Miguel PS
|
|
|
|
|
You may want to try Str Library at http://www.utilitycode.com/str - it does support your scenario
It does work with Borland C++ Builder. By the way, porting code written for Visual C++ to BCB is not trivial - the compilers are quite different
|
|
|
|
|
First lets make sure you have the very latest version. You may always grab that here
http://home.earthlink.net/~jmoleary/code/StdString.zip
Please grab that and try again. I know that my code has successfully built on Borland C++ Builder in the past.
-Joe
p.s. I apologize for taking so long to respond to this. I must have missed the email notification. I only became aware of it after the first response to your question.
|
|
|
|
|
still the same problem (with the latest version too). I think you missed some library however i dont know which. Please help.
When you do things right people wont be sure you have done anything
|
|
|
|
|
Not sure how to proceed with this. Taking a look at the very first error in the message that 'miguelps' provided, I'm confused. It complains about 'mbstate_t' not being a known type. Well 'mbstate_t" is a pretty basic type of the Standard C++ Library. I know I've included the required files. Perhaps there is a namespace issue. Something is fundamentally wrong here but, lacking Borland C++, I don't know how to determine it. My best guess is that the version of the Standard C++ Library that comes with your compiler is not up-to-date. Can you get an update from Borland?
Barring that, can you try the latest GCC?
-Joe
|
|
|
|
|
It surely should be interesting and useful a CString-clone not using Microsoft C++ ...
So I test to compile with gcc (g++, gpp), and I get the following:
==========================================================
Compiler: Default compiler
Executing g++.exe...
g++.exe ".\TestString.cpp" -o ".\TestString.exe" -fexpensive-optimizations -O1 -I"C:\DEV-CPP\include\c++" -I"C:\DEV-CPP\include\c++\mingw32" -I"C:\Dev-Cpp\include\c++\backward" -I"C:\Dev-Cpp\include" -L"C:\DEV-CPP\lib"
In file included from ./TestString.cpp:5:
./StdString.h: In function `int ssvsprintf(WCHAR*, unsigned int, const
WCHAR*, char*)':
./StdString.h:1111: invalid conversion from `size_t' to `const wchar_t*'
./StdString.h:1111: cannot convert `const WCHAR*' to `char*' for argument
`3' to `int vswprintf(wchar_t*, const wchar_t*, char*)'
./StdString.h: At global scope:
./StdString.h:1693: warning: friend declaration `CStdStr<ct>
operator+(const CStdStr<ct>&, const CStdStr<ct>&)' declares a non-template
function
./StdString.h:1693: warning: (if this is not what you intended, make sure
the function template has already been declared and add <> after the
function name here) -Wno-non-template-friend disables this warning
./StdString.h:1694: warning: friend declaration `CStdStr<ct>
operator+(const CStdStr<ct>&, CT)' declares a non-template function
./StdString.h:1695: warning: friend declaration `CStdStr<ct>
operator+(const CStdStr<ct>&, const CHAR*)' declares a non-template function
./StdString.h:1696: warning: friend declaration `CStdStr<ct>
operator+(const CStdStr<ct>&, const WCHAR*)' declares a non-template
function
./StdString.h:1697: warning: friend declaration `CStdStr<ct>
operator+(const CHAR*, const CStdStr<ct>&)' declares a non-template function
./StdString.h:1698: warning: friend declaration `CStdStr<ct>
operator+(const WCHAR*, const CStdStr<ct>&)' declares a non-template
function
In file included from ./TestString.cpp:5:
./StdString.h:3015:31: warning: no newline at end of file
./TestString.cpp: In function `int main(int, char**)':
./TestString.cpp:15: `_bstr_t' undeclared (first use this function)
./TestString.cpp:15: (Each undeclared identifier is reported only once for
each function it appears in.)
./TestString.cpp:26: `_ASSERTE' undeclared (first use this function)
./TestString.cpp:56: no method `CStdStr<char>::SetResourceHandle'
./TestString.cpp:57: `IDS_STRING1' undeclared (first use this function)
./TestString.cpp:60: `IDS_STRING2' undeclared (first use this function)
./StdString.h: In member function `bool CStdStr<ct>::Equals(const CT*,
bool) const [with CT = char]':
./TestString.cpp:27: instantiated from here
./StdString.h:1785: no matching function for call to `ssicmp(
CStdStr<char>, const char*&)'
Execution terminated
==========================================================
How It can be handled ?
Thanks in advance
Miguel PS
|
|
|
|
|
As in the above question, it would appear you have an out-of-date version of the code. Please try to grab the latest version from this link:
http://home.earthlink.net/~jmoleary/code/StdString.zip
This should make things much better. Please let me know if you have any other problems. Clearly I have been lax in following this board but I will be more vigilant in the future.
-Joe
|
|
|
|
|
Hello,
I experienced a small problem with compiling this under linux with g++.
gcc version 3.2.3 20030502 (Red Hat Linux 3.2.3-42)
Compiling:
==================================================
g++ -g -fno-rtti -O3 -c main.cpp -o main.o
In file included from main.cpp:19:
StdString.h: In function `int ssvsprintf(wchar_t*, unsigned int, const
wchar_t*, char*)':
StdString.h:1627: invalid conversion from `const wchar_t*' to `unsigned int'
StdString.h:1627: cannot convert `char*' to `const wchar_t*' for argument `3'
to `int vswprintf(wchar_t*, unsigned int, const wchar_t*, char*)'
main.cpp:48:1: warning: no newline at end of file
make: *** [main.o] Error 1
StdString.h:
-----------------------------------------------------------------------------
1623: #elif defined(__sgi)
1624:
1625: nCount;
1626: return vsprintf( (char *)pW, (char *)pFmtW, vl);
1627:
1628:#else
1629:
1630: nCount;
1631: return vswprintf(pW, pFmtW, vl);
1632:
1633: #endif
-------------
>> man vsprintf
vswprintf - formatted wide character output conversion
int vswprintf(wchar_t *wcs, size_t maxlen,
const wchar_t *format, va_list args);
Solution:
I commented line number 1615 and everything compiled and works fine, so it would be like this:
StdString.h:
#if !defined(_MSC_VER) \
&& !defined (__BORLANDC__) \
1615: //&& !defined(__GNUC__) \
&& !defined(__sgi)
return vswprintf(pW, nCount, pFmtW, vl);
// suddenly with the current SGI 7.3 compiler there is no such function as
// vswprintf and the substitute needs explicit casts to compile
#elif defined(__sgi)
-----------------------------------------------------------------------------------------
It is just a small issue, and everything else works perfectly fine.
And I would like to thank YOU, and all other people, which helped
to create that wonderful class.
I did manage to compile my class, which I wrote under VS7 with CString, using CStdString under Linux without any changes (well, concerning the using of the CString).
THANK YOU.
|
|
|
|
|
Hi,
I'm glad you've had some success with my code. The vsprintf() thing causes a lot of problems and I still have no foolproof solution for all platforms.
There is a somewhat more recent (than CodeProject's) version of the code available at the usual place:
http://home.earthlink.net/~jmoleary/code/StdString.zip.
It includes a minor performance optimization for Replace() and alerts you to possible problems that might occur if you don't have a length-checked formatting function available on your platform
-Joe
-Joe
|
|
|
|
|
I just have a question that if I can use CStdString type of variable where char* is needed. I am afraid it is going to cause crashes. Any help will be greatly appreciated.
|
|
|
|
|
Do you mean where char* is required or const char * ?
For const char* it is no problem. The class has an implicit cast operator to that or you can call c_str() to retrieve the const char* . For example:
<br />
int main(void)<br />
{<br />
<br />
FILE* file = fopen("myfile.txt", "w");<br />
CStdString sName = "Joe";<br />
<br />
<br />
fprintf(file, sName);<br />
<br />
<br />
fprintf(file, sName.c_str());<br />
<br />
return 0;<br />
}<br />
<br />
<br />
For char* you need to be a little more careful since you are effectively giving direct access to the internal buffer of the string class out to another function. To access a CStdtring as a char* you do the same thing you would do with MFC's CString: Call the GetBuffer() function. When access to that internal buffer is no longer needed, call the ReleaseBuffer() function
It is up to you to make sure that you have allocated enough space in the buffer for whatever code you pass it of to. But that's the same problem you would have if you simply allocated a flat char[] array on the stack or got a char* from heap memory. In other words, there is no greater danger using CStrString's internal buffer than there would be using a simple char buffer.
Here's a really dopey example to show how it works.
<br />
<br />
<br />
void GetNameOfCity(char* buf, int nMaxChars)<br />
{<br />
strncpy(buf, "Boston", nMaxChars)<br />
}<br />
<br />
<br />
int main(void)<br />
{<br />
CStdString str;<br />
str.FillStringBuffer(str.GetBuffer(20), 20);<br />
str.ReleaseBuffer();<br />
return 0;<br />
}<br />
<br />
-Joe
|
|
|
|
|
Just a heads up for you Joe, in VS 7.1, when you turn on the compiler option 'Detect 64 bit Portability issues' (option is under Project > Properties > C/C++ > General) StdString.h generates quite a number of warnings. Looks like quite a few static_cast<>'s are needed
|
|
|
|
|
Joe,
many thanks for this class, I've been using it for years with great success.
Right now I'm having difficulty with the SS_NO_REFCOUNT directive, is as much as turning it on prevents compilation. I was wondering if I'd missed something or if indeed there was a problem. This is the compiler error...
c:\dev\fsiv30\platform\microsoft\fsiv30lib\fsilibtest\stdstring.h(2156) : error C2352: 'std::basic_string<char,struct std::char_traits<char="">,class std::allocator<char> >::assign' : illegal call of non-static member function
c:\program files\microsoft visual studio\vc98\include\xstring(132) : see declaration of 'assign'
c:\dev\fsiv30\platform\microsoft\fsiv30lib\fsilibtest\stdstring.h(2144) : while compiling class-template member function 'class CStdStr<char> &__thiscall CStdStr<char>::assign(const char *,unsigned int)'
It occurs on line 2156 of stdstring.h...
Q172398(*this);
>>>>> MYBASE::assign(pC, nChars);
return *this;
If you can offer any feedback I'd appreciate it. I'd rather not go down the route of statically linking the CRT. Right now I'm developing a multithreaded application for Win32 but in the very near future I will need
to develop a similar app for Linux too.
Many thanks
matthew sell
|
|
|
|
|
Hi Matthew,
Sorry to take so long to get back to you.
I'll have to go build my test app tonight with SS_NO_REFCOUNT turned on. I admit it's been awhile since I've done that.
But please be aware, you only need the SS_NO_REFCOUNT setting if you are building with Visual C++ 6.0 with the original version of the Standard C++ Library that came with it. VC7 removes refcounting anyway so it is not needed.
I'll take a look at it tonight or tomorrow night and get back to you
-Joe
-Joe
|
|
|
|
|