读书人

字符串赋值和连接有关问题

发布时间: 2012-01-11 22:28:46 作者: rapoo

字符串赋值和连接问题
这个程序就是拼接两个字符串,但我总觉得不太简便,有没有什么更好的处理方法

int _tmain(int argc, _TCHAR* argv[])
{

TCHAR szDirectory[MAX_PATH];
::GetCurrentDirectory(sizeof(szDirectory), szDirectory);

TCHAR pszPlayer[MAX_PATH];
TCHAR pszSwf[MAX_PATH];
wcscpy(pszPlayer, szDirectory);
wcscpy(pszSwf, szDirectory);

wcscat(pszPlayer, L "\\FlashPlayer.exe ");
wcscat(pszSwf, L "\\main\\template.swf ");

::ShellExecute(NULL, L "open ", pszPlayer, pszSwf, NULL, SW_SHOWNORMAL);

return 0;
}



[解决办法]
sprintf()
[解决办法]
CString 直接相加行不?
[解决办法]
PathCombine
[解决办法]
#include <windows.h>
#include <iostream.h>
#include "Shlwapi.h "

void main( void )
{
// Buffer to hold combined path.
char buffer_1[MAX_PATH] = " ";
char *lpStr1;
lpStr1 = buffer_1;

// String for balance of path name.
char buffer_2[ ] = "One\\Two\\Three ";
char *lpStr2;
lpStr2 = buffer_2;

// String for directory name.
char buffer_3[ ] = "C: ";
char *lpStr3;
lpStr3 = buffer_3;

cout < < "The file path to be combined is "
< < lpStr2 < < endl;
cout < < "The directory name path is "
< < lpStr3 < < endl;
cout < < "The combined path is "
< < PathCombine(lpStr1,lpStr3,lpStr2) < < endl;

}
------------
INPUT:
------------
Path for directory part: "C: "
Path for file part: "One\Two\Three "
------------
OUTPUT:
------------
The file path to be combined is One\Two\Three
The directory name path is C:
The combined path is C:\One\Two\Three


[解决办法]
swprintf(pszPlayer, "%s\\FlashPlayer.exe ",szDirectory);

读书人网 >VC/MFC

热点推荐