I am working on a project where my backend is completely platform independant and I want to keep it that way. So I am using the std::string class in my back end. When my back end sends a std::string to an MFC function as an argument the compiler complains. It seems like there should be some simple way to do this but I am not getting anywhere, so I wrote this quick and dirty function.
CString strToCStr(std::string& s) {
char* buf = new char [s.length() +1];
for(int count = 0; count < s.length() + 1; count++)
{
buf[count] = s[count];
}
CString ret = buf;
delete buf;
return ret;
}
It works but I am not sure if I am going about this the hard way. Can someone help me here? Thanks in advance
CString strToCStr(std::string& s) {
char* buf = new char [s.length() +1];
for(int count = 0; count < s.length() + 1; count++)
{
buf[count] = s[count];
}
CString ret = buf;
delete buf;
return ret;
}
It works but I am not sure if I am going about this the hard way. Can someone help me here? Thanks in advance