2013-03-29 3 views
0

누군가 메시지 상자에 szFileName을 출력하는 방법을 알려주실 수 있습니까?TCHAR 및 문자열 연결을 사용하는 C++ messagebox

//Retrieve the path to the data.dat in the same dir as our app.dll is located 

TCHAR szFileName[MAX_PATH+1]; 
GetModuleFileName(_Module.m_hInst, szFileName, MAX_PATH+1); 
StrCpy(PathFindFileName(szFileName), _T("data.dat")); 

FILE *file =fopen(szFileName,"rb"); 
if (file) 
{ 
    fseek(file,iFirstByteToReadPos, SEEK_SET); 
    fread(bytes,sizeof(unsigned char), iLenCompressedBytes, file); 
    fclose(file); 
} 
else 
{ 
    MessageBox(NULL, szFileName + " not found", NULL, MB_OK); 
    DebugBreak(); 
} 

답변

1

당신은 추가 cannt 작동하지 않습니다 아래 내 시도 :

szFileName + " not found", 

간단한 수정 :

MessageBox(NULL, szFileName, L"File not found", MB_OK); 
1

C++는 '+'지원하지 않는 문자 또는 TCHAR를 연결하는 배열. 이를 위해 문자열 클래스를 사용하거나 스택에 strcat와 버퍼를 사용하여 C 스타일 방식으로 처리해야합니다. 당신은 C++을 사용하고 있기 때문에 당신이 ATL/MFC를 사용하는 경우

, 당신은 CString을 사용할 수 있습니다, 또는 당신은 같은 것을 사용할 수 있습니다

typedef std::basic_string<TCHAR> tstring; 

... 
MessageBox(NULL, tstring(szFileName) + " not found", NULL, MB_OK); 

일반적인 C++를 배관은 독자에게 연습으로 남아있다 .

+2

MessageBox (NULL, (tstring (szFileName) + "찾을 수 없음"). c_str(), NULL, MB_OK); ? – qPCR4vir