About MFC and STL use

zhaozj2021-02-11  243

About the use of MFC and STL Zhao Xiangning Question: I have read the content about STL in a few different places, but I still don't know if it is STL or MFC in my application? My program also handles string, vectors, etc. What is the difference between using STL and MFC? Solution: To answer "which one I should use?" This problem, the answer is almost the same. It relies on what you want to do, the type of your app and your knowledge. It is also important to have your C qualification. When you need to make something quickly, it is best to take advantage of your most familiar tools. If you want to handle the text, you are familiar with MFC, cstring is the first choice. If you are familiar with STL, then use String to replace the MFC. In this world, which one you choose is not important. Use string, list, or a larger class. But sometimes you need to say this or which system takes time. For example, there is an example of an example of an example in a recent article, where I use STL, why? When I started writing this program, I wrote it into a MFC console application - just because I have been applied by a written template console. But after reminding the code (you must often encounter this situation). I am using the MFC CString and CStringList. Because the program is to resolve the command line parameters, Recycle is to create a list of names that delete files, and the file name is CString type. If you only link MFC just to handle strings and lists, you seem to have some waste of resources. CStringList needs to introduce the entire AFXCOLL.OBJ, and CString needs to load strcore.obj, and AFXWININIT must initialize the required modules. If you don't look at the mapping file, you absolutely imagine that the MFC is to load something. In fact, I don't have to look at it. I know that Recycle should use STL efficiency. In order to convert the program to STL and delete all MFC tracking code, I can change the few lines of code. First, I #include and , then add a type definition to convenient, add a type definition: // String list typedef list cstringlist; only the name is the same as MFC, and the interface has been completely changed. Especially STL uses iTerators instead of positions. CStringList files; // file name list ... cstringlist :: item i; for (i = files.begin (); i! = Files.eGin (); i! = Files.end (); i ) {...} Compared, I found STL's Iterators than MFC Positions is easier to memorize. I don't know why, I can't remember the use of positions. Every time I have to check the manual, and Begin / End and i syntax is a light car to me. On the other hand, I hope that the STL has a conversion function to convert String into LPCTSTR, just like cstring: cstring s; // mfclpctstr pstr = s; // call "cString :: operator lpctstr () const; mfc The conversion function is great, using it to pass a CString to any C string that can be used.

转载请注明原文地址:https://www.9cbs.com/read-3868.html

New Post(0)