Mixing CString's and std::string ... yay or nay?
Hello,
I've inherited a C++ project from another guy who's gone on to something else. The project is based on MFC and makes heavy use of MFC's CString class. Personally I prefer std::string, but I'm not sure if adding string.h to the project makes sense seeing as it already has reasonable string support in MFC's CString class. Do you think I should stick with CString or is it okay to use std::string in your opinion?
I know that but I'm afraid I'm stuck with it seeing as large parts of the project have already been written in MFC. :(
Quote:Original post by Nurgle
MFC is teh evil.
I don't really see how this helps the OP at all. Way to spout a meme, though.
I'd stay with CString, personally. It can get real annoying converting between different string classes throughout an app.
I'd say that if it's a large, stable app, keep it; if it's a small project and not very critical (like a little utility and not an application with 1000 customers) it may be easier for you to maintain if you change it to std::string (assuming you know std::string better than CString). If you just want to change it "for the principle of the thing" (or as Nurgle put it "MFC is teh evil") then it is probably not worth the effort. Also, using some parts of the standard C++ library and some parts of MFC may cause your app to grow bigger if that is a concern.
Edit:
Don't forget that if you do decide to change it that you will need to regression test everything that you modified.
Edit:
Don't forget that if you do decide to change it that you will need to regression test everything that you modified.
My point, which was probably to succint for everyone to appreciate, is that RA should invest some time into convert the entire app into something more maintanable and standardized. MFC is not entirely portable, and if the situation should ever arise where the app may need to run in adifferent environment, then he should ease the process as much as possible.
However, IMO, "MFC is teh evil" covers this point of view nicely.
However, IMO, "MFC is teh evil" covers this point of view nicely.
Quote:Original post by Apocryphiliac
I'd say that if it's a large, stable app, keep it; if it's a small project and not very critical (like a little utility and not an application with 1000 customers) it may be easier for you to maintain if you change it to std::string (assuming you know std::string better than CString). If you just want to change it "for the principle of the thing" (or as Nurgle put it "MFC is teh evil") then it is probably not worth the effort. Also, using some parts of the standard C++ library and some parts of MFC may cause your app to grow bigger if that is a concern.
Yeah, those are my main concerns as well. It's actually a fairly important project because a lot of people in my department kinda depend on it (it's a test automation tool for driver software for Siemens drives) so I don't wanna muck around too much with the already existing parts of the project. If I were to use std::string then it would be on top of CString rather than me crawling through the old code and replacing all uses of CString with std::string. But I suppose the old rule if it ain't broken, don't fix it holds true here.
Nurgle, I would be happy to convert the project from MFC to Qt or something else, but I'd probably break a lot of stuff that's already working and it'd take me ages to test and fix everything so I'm gonna stick with MFC.
Anyway, thx for your input, all! =)
We converted all our CStrings to CAtlStrings, which are much more portable than CStrings. We were albe to move the code over to a Mac and the strings worked without modification.
They also follow the same api as CString.
Cheers
Chris
They also follow the same api as CString.
Cheers
Chris
IIRC in MFC7.1 they are quite interchangeable - I'm sure that a constructor exists which takes a std::string. Its been a while tho since I did much in MFC so I could be wrong. (to be honest I thought that in MFC7.1 that CString was a wrapper around std::string - so much functionality of stl and MFC seems to have merged)
Neil
Neil
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement