How to convert a CString
object to integer in MFC.
相关问题
- how to call a C++ dll from C# windows application
- efficiently calling unmanaged method taking unmana
- Why is my COM factory never released during the pr
- Create CFrameWnd gives first-chance exceptions--wh
- Underline is drawn outside of rectangle reported b
相关文章
- C++: Callback typedefs with __stdcall in MSVC
- Is it possible to check whether you are building f
- Which VC++ redistributable package to choose (x86
- MFC CListView响应HDN_ITEMCHANGING后改变列宽无法自动显示隐藏水平滚动条
- How can I handle the Return key in a CEdit control
- How can I create a guid in MFC
- How to convert Byte Array to hex string in visual
- Visual Studio unable to recognise my MFC library f
or
atoi
will work, if you want to convertCString
toint
.Define in msdn: https://msdn.microsoft.com/en-us/library/yd5xkb5c.aspx
CString is wchar_t string. So, if you want convert Cstring to int, you can use:
The canonical solution is to use the C++ Standard Library for the conversion. Depending on the desired return type, the following conversion functions are available: std::stoi, std::stol, or std::stoll (or their unsigned counterparts std::stoul, std::stoull).
The implementation is fairly straight forward:
All of these implementations report errors through exceptions (std::invalid_argument if no conversion could be performed, std::out_of_range if the converted value would fall out of the range of the result type). Constructing the temporary
std::[w]string
can also throw.The implementations can be used for both Unicode as well as MBCS projects.