Can I use CString in a Win32 application ?
-
I developed a program as a Win 32 application (non-MFC) But I found it very difficult to work with string but without CString (MFC). Ex: I can't find a function to cut string from 1 to m (Left()) , a function to cut string from n to m (Mid())... Can I use this MFC class in my program without rewriting in MFC. Can I include this MFC class (.h, .cpp) like a normal class ? Help me !!! Hung Son A Vietnamese student i-g.hypermart.net dlhson2001@yahoo.com
-
I developed a program as a Win 32 application (non-MFC) But I found it very difficult to work with string but without CString (MFC). Ex: I can't find a function to cut string from 1 to m (Left()) , a function to cut string from n to m (Mid())... Can I use this MFC class in my program without rewriting in MFC. Can I include this MFC class (.h, .cpp) like a normal class ? Help me !!! Hung Son A Vietnamese student i-g.hypermart.net dlhson2001@yahoo.com
-
I developed a program as a Win 32 application (non-MFC) But I found it very difficult to work with string but without CString (MFC). Ex: I can't find a function to cut string from 1 to m (Left()) , a function to cut string from n to m (Mid())... Can I use this MFC class in my program without rewriting in MFC. Can I include this MFC class (.h, .cpp) like a normal class ? Help me !!! Hung Son A Vietnamese student i-g.hypermart.net dlhson2001@yahoo.com
-
I developed a program as a Win 32 application (non-MFC) But I found it very difficult to work with string but without CString (MFC). Ex: I can't find a function to cut string from 1 to m (Left()) , a function to cut string from n to m (Mid())... Can I use this MFC class in my program without rewriting in MFC. Can I include this MFC class (.h, .cpp) like a normal class ? Help me !!! Hung Son A Vietnamese student i-g.hypermart.net dlhson2001@yahoo.com
I'd suggest you consider it twice and try to stick with
std::string
s. As for the functions you need, it's simple to write them:std::string mid(const std::string& str,std::string::size_type n,std::string::size_type m)
// extract chars from the n-th position up to the (m-1)-th, indexes are 0-based
{
std::string::size_type count=m<=str.size()?m-n:std::string::npos;
return str.substr(n,count);
}
std::string left(const std::string& str,std::string::size_type n)
// extracts n first leftmost chars
{
std::string::size_type count=n<=str.size()?n:str.size();
return str.substr(0,count);
}
std::string right(const std::string& str,std::string::size_type n)
// extracts n first rightmost chars
{
std::string::size_type count=n<=str.size()?n:str.size();
return str.substr(str.size()-count,count);
}Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
-
I'd suggest you consider it twice and try to stick with
std::string
s. As for the functions you need, it's simple to write them:std::string mid(const std::string& str,std::string::size_type n,std::string::size_type m)
// extract chars from the n-th position up to the (m-1)-th, indexes are 0-based
{
std::string::size_type count=m<=str.size()?m-n:std::string::npos;
return str.substr(n,count);
}
std::string left(const std::string& str,std::string::size_type n)
// extracts n first leftmost chars
{
std::string::size_type count=n<=str.size()?n:str.size();
return str.substr(0,count);
}
std::string right(const std::string& str,std::string::size_type n)
// extracts n first rightmost chars
{
std::string::size_type count=n<=str.size()?n:str.size();
return str.substr(str.size()-count,count);
}Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
-
The resource issue is one reason. The most important objection, though, is of a more profound nature. Adhering to a huge framework for the sake of a tiny utility class like
CString
can cause more harm than good: if you for instance need to port your app to a non-Win32 platform, you'll be regretting you're locked into MFC for such a minute reason. My advice is one should use MFC for what is worth --doing GUI stuff for Windows. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo -
The resource issue is one reason. The most important objection, though, is of a more profound nature. Adhering to a huge framework for the sake of a tiny utility class like
CString
can cause more harm than good: if you for instance need to port your app to a non-Win32 platform, you'll be regretting you're locked into MFC for such a minute reason. My advice is one should use MFC for what is worth --doing GUI stuff for Windows. Joaquín M López Muñoz Telefónica, Investigación y Desarrollothat...and the fact that the original poster said "non-MFC". -c
Cheap oil. It's worth it!
Image Processing - just like mom used to make.
-
I developed a program as a Win 32 application (non-MFC) But I found it very difficult to work with string but without CString (MFC). Ex: I can't find a function to cut string from 1 to m (Left()) , a function to cut string from n to m (Mid())... Can I use this MFC class in my program without rewriting in MFC. Can I include this MFC class (.h, .cpp) like a normal class ? Help me !!! Hung Son A Vietnamese student i-g.hypermart.net dlhson2001@yahoo.com
Instead of adding MFC, use std::string. It has a substr method which does what you're looking for. Christian I am completely intolerant of stupidity. Stupidity is, of course, anything that doesn't conform to my way of thinking. - Jamie Hale - 29/05/2002 Half the reason people switch away from VB is to find out what actually goes on.. and then like me they find out that they weren't quite as good as they thought - they've been nannied. - Alex, 13 June 2002
-
I developed a program as a Win 32 application (non-MFC) But I found it very difficult to work with string but without CString (MFC). Ex: I can't find a function to cut string from 1 to m (Left()) , a function to cut string from n to m (Mid())... Can I use this MFC class in my program without rewriting in MFC. Can I include this MFC class (.h, .cpp) like a normal class ? Help me !!! Hung Son A Vietnamese student i-g.hypermart.net dlhson2001@yahoo.com
If you don't want to use std::string, use WTL which has a CString that works just like MFC's. --Mike-- Just released - RightClick-Encrypt - Adds fast & easy file encryption to Explorer My really out-of-date homepage Sonork-100.19012 Acid_Helm