[問題] CFileFind print問題?

看板C_and_CPP (C/C++)作者時間12年前 (2013/12/11 22:00), 編輯推噓0(0014)
留言14則, 2人參與, 最新討論串1/1
//想問為什麼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

12/11 22:03, , 1F
沒細看,不過你混用了寬字元和 ASCII 字元函式
12/11 22:03, 1F

12/11 22:06, , 2F
所以cout是寬字元?
12/11 22:06, 2F
TRACE(_T("Name of %s is %s\n"), szFileToFind, (LPCTSTR)finder.GetFileName()); 我改成這樣變成沒有顯示任何東西 ※ 編輯: wowrz 來自: 220.141.147.182 (12/11 22:10)

12/11 22:09, , 3F
你有定義 UNICODE 嗎?我 2010 跑很正常
12/11 22:09, 3F

12/11 22:10, , 4F
不過你附的 code 有問題, if 少了一個大括號, 還有我用的
12/11 22:10, 4F

12/11 22:10, , 5F
是 finder.FindNextFileA();
12/11 22:10, 5F

12/11 22:11, , 6F
筆誤,是用 finder.FindNextFile();
12/11 22:11, 6F

12/11 22:11, , 7F
我沒有定義UNICODE
12/11 22:11, 7F

12/11 22:12, , 8F

12/11 22:14, , 9F
連結的程式碼 我跑出來
12/11 22:14, 9F

12/11 22:15, , 10F
Root of 01234488 is 0034BBA8
12/11 22:15, 10F

12/11 22:16, , 11F
先講一下,你原本的code FindNextFileW 是UNICODE,cout是
12/11 22:16, 11F

12/11 22:16, , 12F
ANSI , 我說的混用指的是這裡.然後接下來的問題我沒辦法重
12/11 22:16, 12F

12/11 22:17, , 13F
現,抱歉幫不了你了 Orz
12/11 22:17, 13F

12/11 22:18, , 14F
我覺得應該是project property問題 感謝你...
12/11 22:18, 14F
原來是Property->configuration property ->Character Set要選 Use Multi-BYTE Character set... 應該是我之前不小心動到 ※ 編輯: wowrz 來自: 220.141.147.182 (12/11 22:35)
文章代碼(AID): #1Ig6_kgm (C_and_CPP)
文章代碼(AID): #1Ig6_kgm (C_and_CPP)