CString 轉換集合
CString 轉 string
可能要添加相關的頭檔案,CT2A 它定義在"atlconv.h"中
CString file1;
string filename ;
CT2A xx(file1);
filename = xx;
CString 轉 char*
CString strRootPath;
USES_CONVERSION;
char* chRootPath = T2A(strRootPath);
CString 轉 int
int MinSize = _ttoi(CString cst_MinSize);
CString 轉 float
CString str_data;
float f_data;
f_data=https://bbs.csdn.net/topics/_tstof(str_data);
/ * ------------------------------------------------------------------------------------------------------------------------ */
string 轉換集合
string 轉 char*
char* p = (char*)(strpath.c_str())
string 轉 float
string str_data="https://bbs.csdn.net/topics/12345";
float f_data;
f_data=https://bbs.csdn.net/topics/ atof( str_data.c_str() );
string 轉 int
int n = atoi(str.c_str());
uj5u.com熱心網友回復:
多謝分享
uj5u.com熱心網友回復:
字串那些事兒:BSTR-LPSTR-LPWSTR-CString-VARIANT-COleVariant-_variant_t-CComBSTR-_bstr_thttp://blog.csdn.net/pizi0475/archive/2010/03/04/5346708.aspx
uj5u.com熱心網友回復:
如果記得沒錯的話,T2A好像有個長度的限制,1024吧,最好WCHAR*轉char*還是使用WideCharToMultiByte()函式uj5u.com熱心網友回復:
include\atlconv.h:
#define W2A(lpw) (\
((_lpw = lpw) == NULL) ? NULL : (\
(_convert = (lstrlenW(_lpw)+1), \
(_convert>INT_MAX/2) ? NULL : \
ATLW2AHELPER((LPSTR) alloca(_convert*sizeof(WCHAR)), _lpw, _convert*sizeof(WCHAR), _acp))))
……
#define T2A W2A
……
綜上所述,T2A的長度受alloca能分配的最大位元組數限制:
/STACK (Stack Allocations)
Home | Overview | How Do I | Linker Options
The Stack Allocations (/STACK:reserve[,commit]) option sets the size of the stack in bytes.
To find this option in the development environment, click Settings on the Project menu. Then click the Link tab, and click Output in the Category box. The Reserve text box (or in the reserve argument on the command line) specifies the total stack allocation in virtual memory. The default stack size is 1 MB. The linker rounds up the specified value to the nearest 4 bytes.
The optional value specified in the Commit text box (or in the commit argument on the command line) is subject to interpretation by the operating system. In Windows NT, it specifies the amount of physical memory to allocate at a time. Committed virtual memory causes space to be reserved in the paging file. A higher commit value saves time when the application needs more stack space, but increases the memory requirements and possibly the startup time.
Specify the reserve and commit values in decimal or C-language notation.
Another way to set the size of the stack is with the STACKSIZE statement in a module-definition (.DEF) file. STACKSIZE overrides the Stack Allocations (/STACK) option if both are specified. You can change the stack after the .EXE file is built by using the EDITBIN tool.
uj5u.com熱心網友回復:
66666666666666uj5u.com熱心網友回復:
我是這樣在 CString 與 string 之間轉換的:從 CString 到 string,如果是UNICODE 工程:
CString strSource;
CStringA strTmp;
std::string target;
strTmp = strSource;
target = strTmp.GetString();
如果是非 UNICODE 工程,下面直接 target = strSource.GetString();
從 string 到 CString 就簡單了
std::string src;
CString target;
target = src.c_str();
uj5u.com熱心網友回復:
66666,之前搞VC的時候,這些型別轉換真頭疼。uj5u.com熱心網友回復:
T2A這類的轉換方發有記憶體泄露,在回圈里不要用這個去轉,另外在unicode和多字符集下,轉換方式也不同uj5u.com熱心網友回復:
uj5u.com熱心網友回復:
謝謝分享!!!!uj5u.com熱心網友回復:
MARK.....uj5u.com熱心網友回復:
uj5u.com熱心網友回復:
string類的成員函式c_str()回傳的是const char*型別,你強制把它轉換成char*型別是很不安全的,而且在C++中應該盡量避免使用這種老式的強制型別轉換語法。另外我覺得一般情況下并不需要將string類轉換成char*,更多情況下需要將其轉換成const char*,這種情況下直接呼叫c_str()函式即可。轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/111036.html
標籤:基礎類
上一篇:怎樣自動售賣虛擬產品?
下一篇:套接字編程問題
