C 讀取配置檔案

2021-09-29 16:10:24 字數 699 閱讀 3623

1 利用系統介面,讀取ini配置檔案,詳情可查詢msdn。這裡做簡單宣告

//宣告讀ini檔案的api函式

[dllimport("kernel32")]

private static extern int getprivateprofilestring(string section, string key, string def, stringbuilder retval, int size, string filepath);

2 使用的話,可以這樣

stringbuilder strcfgsecssion = null;

fileinfo inifile = null;

try

3 如果你需要的是int型別的值得話,你可以這樣取

this.m_iport_server = int.parse(strcfgsecssion.tostring());
4 順便囉嗦一句,配置檔案的內容是這個樣子的。那個;後面是配置檔案的注釋,檔名是程式乙個目錄下的test.ini

;伺服器設定

[mailset]

;伺服器ip位址

serverip=192.168.1.2

;伺服器端口

serverport=250

C 讀取配置檔案

1 首先引入標頭檔案 include 2 獲取應用程式的當前路徑 char buf 1000 getcurrentdirectory 1000,buf 得到當前工作路徑3 獲取配置檔案的路徑 char path 1024 definesysconfig config.ini sprintf path...

C讀取配置檔案

ifndef cfg op h define cfg op h ifdef cplusplus extern c endif endif define crt secure no warnings include include include define maxline 2048 獲取配置項 i...

C 讀取ini配置檔案

using system using system.io using system.runtime.interopservices using system.text todo 在此處新增建構函式邏輯 public class iniclass 寫入ini檔案 專案名稱 如 typename 鍵 值...