stl version of CString?
-
First off: STL RULES! Ok, now a confession... the only reason I even use MFC is for CString. I've been searching for a decent stl replacement, and found a few, but I thought I'd ask some STL zealots for their respective opinions... - Nitron
"Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb
-
First off: STL RULES! Ok, now a confession... the only reason I even use MFC is for CString. I've been searching for a decent stl replacement, and found a few, but I thought I'd ask some STL zealots for their respective opinions... - Nitron
"Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb
A quick & dirty replacement is:
typedef std::basic_string<TCHAR> tstring;
although I think I've seen a true STL port here on CP. --Mike-- The Internet is a place where absolutely nothing happens. -- Strong Bad 1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click! My really out-of-date homepage Sonork-100.19012 Acid_Helm
-
A quick & dirty replacement is:
typedef std::basic_string<TCHAR> tstring;
although I think I've seen a true STL port here on CP. --Mike-- The Internet is a place where absolutely nothing happens. -- Strong Bad 1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click! My really out-of-date homepage Sonork-100.19012 Acid_Helm
Michael Dunn wrote: typedef std::basic_string<TCHAR> tstring; That's not enough. CString uses reference counting remember? Best regards, Alexandru Savescu P.S. Interested in art? Visit this!
-
Michael Dunn wrote: typedef std::basic_string<TCHAR> tstring; That's not enough. CString uses reference counting remember? Best regards, Alexandru Savescu P.S. Interested in art? Visit this!
Well, depending on your application, reference counting can be slower. Herb Sutter did a study and found that reference counting based strings only benefit the application if you application is primarily copying the string from place to place without modification. But you also have to take into account any memory savings that you might get with a reference counting system. Tim Smith I'm going to patent thought. I have yet to see any prior art.
-
A quick & dirty replacement is:
typedef std::basic_string<TCHAR> tstring;
although I think I've seen a true STL port here on CP. --Mike-- The Internet is a place where absolutely nothing happens. -- Strong Bad 1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click! My really out-of-date homepage Sonork-100.19012 Acid_Helm
Actually, to be even more specific, I use CString mainly for the method:
szMyString.Format("My unsigned int is 0x%.8X", uiMyInt);
...and for some reason sprintf() scares me :~ - Nitron
"Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb
-
Actually, to be even more specific, I use CString mainly for the method:
szMyString.Format("My unsigned int is 0x%.8X", uiMyInt);
...and for some reason sprintf() scares me :~ - Nitron
"Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb
std::ostringstream oss;
oss << "My unsigned int is 0x" << std::uppercase << std::setw ( 8 )
<< std::setfill ( '0' ) << std::hex << n << std::endl;
std::cout << oss.str () << std::endl;Is roughly the equivalent when using the STLs. It a bit of a mouth full, but some of the modifiers persist between calls--
std::uppercase
will, whilestd::setw
must be called each time--so once you called them, you need not do so again untill you need a new option set. cheers, -B -
std::ostringstream oss;
oss << "My unsigned int is 0x" << std::uppercase << std::setw ( 8 )
<< std::setfill ( '0' ) << std::hex << n << std::endl;
std::cout << oss.str () << std::endl;Is roughly the equivalent when using the STLs. It a bit of a mouth full, but some of the modifiers persist between calls--
std::uppercase
will, whilestd::setw
must be called each time--so once you called them, you need not do so again untill you need a new option set. cheers, -BBen Burnett wrote: It a bit of a mouth full, I agree. Maybe I will have to attempt my own STL replacement for CString... hmmm, possible article :suss: - Nitron
"Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb
-
Ben Burnett wrote: It a bit of a mouth full, I agree. Maybe I will have to attempt my own STL replacement for CString... hmmm, possible article :suss: - Nitron
"Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb
Nitron wrote: Maybe I will have to attempt my own STL replacement for CString... Before you dig in, check out the Boost Format library[^]. It might just be what you're looking for. cheers, -B
-
Ben Burnett wrote: It a bit of a mouth full, I agree. Maybe I will have to attempt my own STL replacement for CString... hmmm, possible article :suss: - Nitron
"Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb
Nitron wrote: Maybe I will have to attempt my own STL replacement for CString... Sounds like more than one nights worth of work. ;)
Nick Parker
The only man who never makes a mistake is the man who never does anything. - Theodore Roosevelt