看板 C_and_CPP 關於我們 聯絡資訊
開發平台(Platform): (Ex: Win10, Linux, ...) Win10 編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出) vs2019 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) 問題(Question): 各位大大好,最近因為在做設定檔案的取值, 之前我的作法都是採用:GetPrivateProfileString(只需要輸入Section與KenName即可) 之後跟同事開會,有注意到一個問題,如果資料量太大,一個一個輸入效率太低。 所以我找到有關於GetPrivateProfileSection (只需要輸入Section,即可顯示此類組所有KeyName與KeyValue) 測試的時候,確認有資料,但顯示為什麼都是一堆我不懂的數字.....? 餵入的資料(Input): 下圖是我的設定檔案的內容,主要是抓取"System Access"、"Registry Values" 這兩大類,我先實驗只抓取"System Access"這個類組的資料 https://imgur.com/37gMtJw 預期的正確結果(Expected Output): 這邊我預想是顯示: MinimumPasswordAge = 0 MaximumPasswordAge = 42 MinimumPasswordLength = 0 PasswordComplexity = 0 PasswordHistorySize = 0 LockoutBadCount = 0 RequireLogonToChangePassword = 0 ForceLogoffWhenHourExpire = 0 NewAdministratorName = "Administrator" NewGuestName = "Guest" ClearTextPassword = 0 LSAAnonymousNameLookup = 0 EnableAdminAccount = 0 EnableGuestAccount = 0 錯誤結果(Wrong Output): 下圖是直接顯示的結果,不懂為什麼出現一個我看不懂的數值 https://imgur.com/FKSnk9U 程式碼(Code):(請善用置底文網頁, 記得排版,禁止使用圖檔) #include <iostream> #include <windows.h> #include <fstream> #include <vector> #include <stdio.h> #include <string> #include <sstream> #include <tchar.h> #include <shellapi.h> #include <sys/types.h> #include <sys/stat.h> #include <atlstr.h> #include <codecvt> int main(void) { TCHAR strRetunrStringBuf[512]; TCHAR* strNavi[512]; GetPrivateProfileSection(_T("System Access"), strRetunrStringBuf, 512, Get_LGPO01_FilePath()); cout<< strRetunrStringBuf <<endl; } //Get_LGPO01_FilePath是我預先寫好檔案路徑的位置,所以可以直接使用 補充說明(Supplement): 一開始我以為是我方向錯誤,我檢查了strRetunrStringBuf內有顯示的東西: https://imgur.com/VzpgO87 它內容其實是有抓到我指定類組的資料,並以'\0'作為區分 https://imgur.com/i0aesxx 但我不不懂他這一整個內容呈現會是一個奇怪的數字??? 想詢問各位大神們,是我哪邊搞錯了嗎? -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 218.161.102.123 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1569392481.A.134.html
steve8625: wchar_t塞進cout會印壞, 用wcout 09/25 15:59
steve8625: 但這樣只能印出第一個wstring, 要用迴圈處理一下 09/25 16:01
steve8625: GetPrivateProfileSection會給你他吃了多長的資料進來 09/25 16:02
感恩感恩~我稍微理解她回傳的東西了 我再想想看該怎麼改~! 感謝您~我再試試看 ※ 編輯: jayzhuang (218.161.102.123 臺灣), 09/26/2019 13:48:48