作者wowrz ()
看板C_and_CPP
標題[問題] CFileFind print問題?
時間Wed Dec 11 22:00:10 2013
//想問為什麼cout<<PATH會變成011E2FAB像是其它進制的表示??
//
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include <fstream>
#include <string>
#include <tchar.h>
#include <afx.h>
#include <iostream>
#include <stdio.h>
//首先我載入了這些標頭檔
using namespace std;
CFileFind finder;
static const TCHAR szFileToFind[] = _T("C:\\WINDOWS\\SYSTEM.INI");
void main(){
BOOL bResult = finder.FindFile(szFileToFind);
if (bResult)
{
finder.FindNextFileW();
///////////////////////////////////////////////////我的Print指令
cout << "Root of " << szFileToFind;
cout << " is " << (LPCTSTR)finder.GetRoot();
cout << endl;
///////////////////////////////////////////////////我的Print指令
finder.Close();
}
else
cout << "You have no " << szFileToFind << " file." << endl;
getchar();
}
//我最後執行輸出變成:
//Root of 011E2FAB is 005165D0
//照理來說是不是要像下面:
//Root of C:\WINDOWS\SYSTEM.INI is C:\WINDOWS
//?
//------------------環境-------------------------------------
//1.我使用的是VC 2013 (VC2010我也試過了)
//2.property ->configuration property->general ->use of MFC
// 我有改成->Use MFC in a Shared DLL
//---------------------------------------------------------
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 220.141.147.182
→ EdisonX:沒細看,不過你混用了寬字元和 ASCII 字元函式 12/11 22:03
→ wowrz:所以cout是寬字元? 12/11 22:06
TRACE(_T("Name of %s is %s\n"), szFileToFind,
(LPCTSTR)finder.GetFileName());
我改成這樣變成沒有顯示任何東西
※ 編輯: wowrz 來自: 220.141.147.182 (12/11 22:10)
→ EdisonX:你有定義 UNICODE 嗎?我 2010 跑很正常 12/11 22:09
→ EdisonX:不過你附的 code 有問題, if 少了一個大括號, 還有我用的 12/11 22:10
→ EdisonX:是 finder.FindNextFileA(); 12/11 22:10
→ EdisonX:筆誤,是用 finder.FindNextFile(); 12/11 22:11
→ wowrz:我沒有定義UNICODE 12/11 22:11
→ wowrz:連結的程式碼 我跑出來 12/11 22:14
→ wowrz:Root of 01234488 is 0034BBA8 12/11 22:15
→ EdisonX:先講一下,你原本的code FindNextFileW 是UNICODE,cout是 12/11 22:16
→ EdisonX:ANSI , 我說的混用指的是這裡.然後接下來的問題我沒辦法重 12/11 22:16
→ EdisonX:現,抱歉幫不了你了 Orz 12/11 22:17
→ wowrz:我覺得應該是project property問題 感謝你... 12/11 22:18
原來是Property->configuration property ->Character Set要選 Use Multi-BYTE
Character set...
應該是我之前不小心動到
※ 編輯: wowrz 來自: 220.141.147.182 (12/11 22:35)