 |
|
 |
Hi,
Great article. But the class is missing CStringT::Tokenize.
/Mizan
|
|
|
|
 |
|
|
 |
|
 |
There seems to be an issue with the Trim functions because you use the std::isspace which for Dinkumware in VC6 which doesn't accurately handle international characters properly. I've changed it to use isspace instead but perhaps for somebody else with the same issue something to take into consideration.
Update:
Seems only
bool bRet = std::isspace((WCHAR)L"Ö", std::locale());
has the problem so really only an issue with UNICODE builds.
Karl
modified 4 Mar '12.
|
|
|
|
 |
|
 |
Hey thanks for that. I wasn't aware there was an issue. In the next update I make (which I keep promising but not delivering...) I will put an #ifdef check in there for _MSC_VER that uses regular old isspace for VC6
-Joe
|
|
|
|
 |
|
 |
Yeah seems to be a rounding issue of some kind, if you change it to (int) or (CHAR), it works fine but seeing the UNICODE one is basically basic_string probably why it happens.
Karl
|
|
|
|
 |
|
 |
Hi,
this is one of THE best piece of code concerning strings and C++. I currently use MFC and formatting is around 100% faster with this code. However there is one shortage. MFC CString only uses 4 bytes when holding no string, while CStdString uses 28. When using it in large arrays this makes big difference. Is there a way to optimize this (without sacrifice anything else)?
Best regards,
Bostjan Erzen
|
|
|
|
 |
|
 |
Hi Bostjan,
I'm glad you like the code,
Unfortunately, this memory footprint is something over which I have no control. My code adds no memory to the base class (basic_string) and performs no allocations for an empty string. Those 28 bytes (I think they're 32 bytes in release mode...) are completely allocated by Microsoft's own implementation of the basic_string template.
They chose an approach that gives each string object a small, internal buffer, by default. The idea was to minimize memory allocations for short strings. While it certainly helps in that case, it creates a big default size. You can read about the issue here:
http://social.msdn.microsoft.com/forums/en-US/vclanguage/thread/9a59970d-c7bf-4ed5-8267-e482c4e461a7/[^]
The only way I can think of to get around this is to use an alternate implementation of the Standard C++ Library, like, perhaps the STLPort implementation - http://www.stlport.org
Sorry. I really have no ability to get around this problem. I can't edit the base class code (nor would anyone want me to!)
-Joe
-Joe
|
|
|
|
 |
|
 |
Just what I was looking for ... but no way to make it work. Using a Windows/7 system.
First it asked me for crtdbg.h, which I don't have. Google tells me to install MicroSoft SDK.
I tried ... but it asks for Visual C++ 8 SP1.
I tried installing VC 8 SP1 but it asks for a full version of VC 8 (not Express), so this is not free software.
And I thought that the whole class didn't need any previous VS!
Found a crtdbg.h and copied it to the local folder.
Now I get dozens of errors (deleted all warnings):
C:\Users\Enric\Documents\ButiNET\Test\stdstring.h||In function 'int ssvsprintf(WCHAR*, size_t, const WCHAR*, char*)':|
C:\Users\Enric\Documents\ButiNET\Test\stdstring.h|1673|error: invalid conversion from 'size_t' to 'const wchar_t*'|
C:\Users\Enric\Documents\ButiNET\Test\stdstring.h|1673|error: cannot convert 'const WCHAR*' to 'char*' for argument '3' to 'int vswprintf(wchar_t*, const wchar_t*, char*)'|
C:\Users\Enric\Documents\ButiNET\Test\stdstring.h||In member function 'void CStdStr<CT>::FormatV(const CT*, char*)':|
C:\Users\Enric\Documents\ButiNET\Test\stdstring.h|3183|error: 'size_type' was not declared in this scope|
C:\Users\Enric\Documents\ButiNET\Test\stdstring.h|3183|error: expected ';' before 'nActual'|
C:\Users\Enric\Documents\ButiNET\Test\stdstring.h|3191|error: there are no arguments to '_alloca' that depend on a template parameter, so a declaration of '_alloca' must be available|
C:\Users\Enric\Documents\ButiNET\Test\stdstring.h|3191|note: (if you use '-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated)|
C:\Users\Enric\Documents\ButiNET\Test\stdstring.h|3196|error: 'nActual' was not declared in this scope|
C:\Users\Enric\Documents\ButiNET\Test\stdstring.h|3204|error: 'nActual' was not declared in this scope|
C:\Users\Enric\Documents\ButiNET\Test\stdstring.h||In member function 'void CStdStr<CT>::FormatMessageA(typename std::basic_string<_CharT, std::char_traits<_CharT>, std::allocator<_CharT> >::const_pointer, ...)':|
C:\Users\Enric\Documents\ButiNET\Test\stdstring.h|3310|error: 'runtime_error' is not a member of 'std'|
C:\Users\Enric\Documents\ButiNET\Test\stdstring.h||In member function 'void CStdStr<CT>::FormatMessageA(UINT, ...)':|
C:\Users\Enric\Documents\ButiNET\Test\stdstring.h|3329|error: 'runtime_error' is not a member of 'std'|
C:\Users\Enric\Documents\ButiNET\Test\stdstring.h||In member function 'OLECHAR* CStdStr<CT>::SetSysString(OLECHAR**) const':|
C:\Users\Enric\Documents\ButiNET\Test\stdstring.h|3571|error: 'runtime_error' is not a member of 'std'|
C:\Users\Enric\Documents\ButiNET\Test\stdstring.h||In member function 'void CStdStr<CT>::CharToOemA()':|
C:\Users\Enric\Documents\ButiNET\Test\stdstring.h|3599|error: there are no arguments to 'empty' that depend on a template parameter, so a declaration of 'empty' must be available|
C:\Users\Enric\Documents\ButiNET\Test\stdstring.h||In member function 'void CStdStr<CT>::OemToCharA()':|
C:\Users\Enric\Documents\ButiNET\Test\stdstring.h|3612|error: there are no arguments to 'empty' that depend on a template parameter, so a declaration of 'empty' must be available|
C:\Users\Enric\Documents\ButiNET\Test\stdstring.h|3880|error: there are no arguments to 'SSResourceHandle' that depend on a template parameter, so a declaration of 'SSResourceHandle' must be available|
C:\Users\Enric\Documents\ButiNET\Test\stdstring.h|3884|error: there are no arguments to 'SSResourceHandle' that depend on a template parameter, so a declaration of 'SSResourceHandle' must be available|
Any idea?
Thks
|
|
|
|
 |
|
 |
First let me figure out what you are using. What compiler are you using? Visual C++? If so, what version? 2008? 2010? 2005?
I have all 3 of those on my box. If you are having troubles, can you send me a zipped up copy of the test project you are using? I should be able to figure it out
-Joe
|
|
|
|
 |
|
 |
No, I'm not using any VC version.
I never installed VC on my W/7 computer, but for some reason there are several VC5/VC8 redistributables on the list of installed programs. I tried to install VC 2010 Express but it fails, Google says "uninstall VC8" but I cannot unistall any of them, all unistall attempts end up with error: either windows install service unavailable, or install source unavailable. So seems I'm blocked somehow
I use Code::Blocks with GNU GCC compiler. I just created a new project with nothing else than the stdstring.h and a main.
|
|
|
|
 |
|
 |
Ah, GNU. OK,
Well first of all, to get around the code trying to include crtdbg.h, tell it to go ANSI-only by adding the following line somewhere near the top of the file
#define SS_ANSI
If you still have problems with the vsnprintf function showing up in your output, take a look at the comments I put there. The function seems to have different signatures depending on the platform. I have some conditional #ifdefs around it, trying to make it select the right one based off of the platform but those are far from perfect.
I'm afraid I can't help you with the uninstalling of Visual C++
-Joe
|
|
|
|
 |
|
 |
Solved.
The #define gets rid of the crtdbg problem.
I changed
return vswprintf(pW, pFmtW, vl);
and everything seems to work.
Ten points for your code!
Thks
|
|
|
|
 |
|
 |
If you need to email me directly, my email address is the earthlink one at the top of the header file. It still works. I've had it for 16 years!
-Joe
|
|
|
|
 |
|
|
 |
|
 |
I must admit, my version is still missing a couple of CString functions that were added in later version. Functions like Tokenize and GetString. I've added them to my local version and hope to do another update here as soon as possible.
-Joe
|
|
|
|
 |
|
 |
When will we see an updated version with these functions added?
Your code sure makes porting code a lot easier, but it would really help to get the last few functions implemented.
|
|
|
|
 |
|
 |
I've been using CStdString for many years now across many projects. I really like how I can write full-features and portable code.
|
|
|
|
 |
|
 |
I tried to build in Visual Studio 2010 Professional and got following unresolve.
1>TestString.obj : error LNK2019: unresolved external symbol "class CStdStr<char> __cdecl operator+(class CStdStr<char> const &,char const *)" (??H@YA?AV?$CStdStr@D@@ABV0@PBD@Z) referenced in function _main
1>.\Debug\TestString.exe : fatal error LNK1120: 1 unresolved externals
|
|
|
|
 |
|
 |
Oh are you trying the the test project download? Sorry but *that* one, I must admit, is truly out of date. I just updated the stdstring.h individual download, not the test project (yet).
I hope to update that tonight but in the meantime, Try replacing the stdstring.h header that is in the test project with the up-to-date version from the individual download
-Joe
|
|
|
|
 |
|
 |
Based on the recent discussions the code has been updated to fix bugs. The datein the submitted code is of 2001. Please update the latest code here or post a URL where it can be downloaded.
|
|
|
|
 |
|
 |
No the date of the latest code is just a couple of days ago
-Joe
|
|
|
|
 |
|
 |
Yes, you are correct. Please accept my apologies.
|
|
|
|
 |
|
 |
Hi, does this work also with gcc? I'm using eclipse in ubuntu and got several (35) compilation errors.
I'm a c++ newbye...
|
|
|
|
 |
|
 |
Hi,
I would bet good money that any compilation errors you are having mention something about the function vsnprintf or vswprintf. The only problem I seem to see these days with the CStdString is with different, non-standard versions of these functions. It seems to depend upon the compiler/C++ distribution. I have a mass of #ifdef-s in there checking various versions but it's still not perfect
Regardless I am pretty sure I can help you resolve them. Just email me directly (my email address is the earthlink one at the top of the header file) and send the text of of all the error messages. If I learn anything of general use, I will fix the header and post it back here.
-Joe
-Joe
|
|
|
|
 |
|
 |
1.
CString str = '"'; //it`s ok
CStdString str = '"'; //error C2440: "initialize": not from the "char" into "CStdStr "
2.
char GetDrive ()
{
char sz [MAX_PATH] = "";
GetModuleFileName (NULL, sz, MAX_PATH);
return sz [0];
}
CString path = CString(GetDrive ()) + ":";//it`s ok
CStdString path = CStdString(GetDrive ()) + ":"; //error C2440: "": not from the "char" into "CStdString"
|
|
|
|
 |