c读取指定配置文件|C语言如何读取文件中指定的某一段

|

⑴ c语言读写配置文件

#include <stdio.h>#include <string.h>#define MAX_BUF 20#define SERVER "localhost"#define CONFIG_FILE "1.conf"bool SetAuthServer(char* strServerAdd){ char buf[MAX_BUF], tempBuf[MAX_BUF]; memset(buf, 0, MAX_BUF); memset(tempBuf, 0, MAX_BUF); FILE *pF = fopen(CONFIG_FILE, "r"); if(!pF) { printf("打开文件失败!\n"); return false; } fread(buf, MAX_BUF, 1, pF); if(!feof(pF)) { printf("读取不完整,请把MAX_BUF设置为大一点, 当前大小为: %d\n", MAX_BUF); fclose(pF); return false; } fclose(pF); char *lpPos = buf; char *lpNewPos = buf; while(lpNewPos = strstr(lpPos, SERVER)) { strncpy(tempBuf+strlen(tempBuf), lpPos, lpNewPos-lpPos); strcat(tempBuf, strServerAdd); lpPos = lpNewPos + strlen(SERVER); } strcat(tempBuf, lpPos); pF = fopen(CONFIG_FILE, "w"); if(!pF) { printf("打开文件失败!\n"); return false; } fwrite(tempBuf, strlen(tempBuf), 1, pF); fclose(pF); return true;}void main(){ char buf[20]; printf("请输入一个字符串来修改服务器配置: "); scanf("%s", buf); if(SetAuthServer(buf) == true) printf("修改成功!\n"); else printf("修改失败!\n"); }

⑵ C怎样读取配置文件并设成环境变量

右键单机“我的电脑”选择“属性”,在出来的新界面中选择左边的菜单“高级系统设置”,会弹出一个框框,框框里面的最下面就有环境变量的编辑,你只要将你的环境变量丢里面去就行了。

⑶ C#如何读取config配置文件数据

代码如下:usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Text.RegularExpressions;usingSystem.Configuration;usingSystem.ServiceModel;usingSystem.ServiceModel.Configuration;namespaceNetUtilityLib{publicstaticclassConfigHelper{//依据连接串名字connectionName返回数据连接字符串(stringconnectionName){//指定config文件读取stringfile=System.Windows.Forms.Application.ExecutablePath;System.Configuration.Configurationconfig=ConfigurationManager.OpenExeConfiguration(file);stringconnectionString=config.ConnectionStrings.ConnectionStrings[connectionName].ConnectionString.ToString();returnconnectionString;}///<summary>///更新连接字符串///</summary>///<paramname="newName">连接字符串名称</param>///<paramname="newConString">连接字符串内容</param>///<paramname="newProviderName">数据提供程序名称</param>(stringnewName,stringnewConString,stringnewProviderName){//指定config文件读取stringfile=System.Windows.Forms.Application.ExecutablePath;Configurationconfig=ConfigurationManager.OpenExeConfiguration(file);boolexist=false;//记录该连接串是否已经存在//如果要更改的连接串已经存在if(config.ConnectionStrings.ConnectionStrings[newName]!=null){exist=true;}//如果连接串已存在,首先删除它if(exist){config.ConnectionStrings.ConnectionStrings.Remove(newName);}//新建一个连接字符串实例=newConnectionStringSettings(newName,newConString,newProviderName);//将新的连接串添加到配置文件中.config.ConnectionStrings.ConnectionStrings.Add(mySettings);//保存对配置文件所作的更改config.Save(ConfigurationSaveMode.Modified);//强制重新载入配置文件的ConnectionStrings配置节ConfigurationManager.RefreshSection("ConnectionStrings");}///<summary>///返回*.exe.config文件中appSettings配置节的value项///</summary>///<paramname="strKey"></param>///<returns></returns>(stringstrKey){stringfile=System.Windows.Forms.Application.ExecutablePath;Configurationconfig=ConfigurationManager.OpenExeConfiguration(file);foreach(stringkeyinconfig.AppSettings.Settings.AllKeys){if(key==strKey){returnconfig.AppSettings.Settings[strKey].Value.ToString();}}returnnull;}///<summary>///在*.exe.config文件中appSettings配置节增加一对键值对///</summary>///<paramname="newKey"></param>///<paramname="newValue"></param>(stringnewKey,stringnewValue){stringfile=System.Windows.Forms.Application.ExecutablePath;Configurationconfig=ConfigurationManager.OpenExeConfiguration(file);boolexist=false;foreach(stringkeyinconfig.AppSettings.Settings.AllKeys){if(key==newKey){exist=true;}}if(exist){config.AppSettings.Settings.Remove(newKey);}config.AppSettings.Settings.Add(newKey,newValue);config.Save(ConfigurationSaveMode.Modified);ConfigurationManager.RefreshSection("appSettings");}//修改system.serviceModel下所有服务终结点的IP地址(stringconfigPath,stringserverIP){Configurationconfig=ConfigurationManager.OpenExeConfiguration(configPath);ConfigurationSectionGroupsec=config.SectionGroups["system.serviceModel"];=secasServiceModelSectionGroup;ClientSectionclientSection=serviceModelSectionGroup.Client;foreach(.Endpoints){stringpattern=@"d{1,3}.d{1,3}.d{1,3}.d{1,3}";stringaddress=item.Address.ToString();stringreplacement=string.Format("{0}",serverIP);address=Regex.Replace(address,pattern,replacement);item.Address=newUri(address);}config.Save(ConfigurationSaveMode.Modified);ConfigurationManager.RefreshSection("system.serviceModel");}//修改applicationSettings中App.Properties.Settings中服务的IP地址publicstaticvoidUpdateConfig(stringconfigPath,stringserverIP){Configurationconfig=ConfigurationManager.OpenExeConfiguration(configPath);ConfigurationSectionGroupsec=config.SectionGroups["applicationSettings"];=sec.Sections["DataService.Properties.Settings"];=;if(clientSettingsSection!=null){SettingElementelement1=clientSettingsSection.Settings.Get("DataService_SystemManagerWS_SystemManagerWS");if(element1!=null){clientSettingsSection.Settings.Remove(element1);stringoldValue=element1.Value.ValueXml.InnerXml;element1.Value.ValueXml.InnerXml=GetNewIP(oldValue,serverIP);clientSettingsSection.Settings.Add(element1);}SettingElementelement2=clientSettingsSection.Settings.Get("DataService_EquipManagerWS_EquipManagerWS");if(element2!=null){clientSettingsSection.Settings.Remove(element2);stringoldValue=element2.Value.ValueXml.InnerXml;element2.Value.ValueXml.InnerXml=GetNewIP(oldValue,serverIP);clientSettingsSection.Settings.Add(element2);}}config.Save(ConfigurationSaveMode.Modified);ConfigurationManager.RefreshSection("applicationSettings");}privatestaticstringGetNewIP(stringoldValue,stringserverIP){stringpattern=@"d{1,3}.d{1,3}.d{1,3}.d{1,3}";stringreplacement=string.Format("{0}",serverIP);stringnewvalue=Regex.Replace(oldValue,pattern,replacement);returnnewvalue;}}}

⑷ C语言如何读取文件中指定的某一段

使用fread函数读取指定长度的字符串,即使包含\n也会被读取,可以首先使用fseek定位到文件结尾,然后ftell函数返回的值就是文件的大小,这样就可以用循环多次读取文件,直到读取所有内容FILE *file = NULL;char szFile[1025] = {0};int nHadRead = 0;file = fopen( "file.txt", "r+");if ( file == NULL )return;fseek( file, 0, SEEK_END ); //定位到文件尾int nLen = ftell( file ); //获取当前位置,即文件长度fseek( file 0, SEEK_SET ); //重新定位到文件开头,准备开始读while ( nHadRead < nLen ){int nRead = nLen – nHadRead >1024 ? 1024 : nLen – nHadRead;//如果剩余小于1024字节,则读剩余字节,否则每次读取1024字节。int nTmp = fread( szFile, 1, nRead , file );nHadRead += nTmp;printf( "%s", szFile );memset( szFile, 0x0, sizeof(szFile) );}fclose(file);大致过程就是这样,纯手打,没有调试过,可能有错

⑸ 用C#如何读写配置文件

INI文件就是扩展名为”ini”的文件。x0dx0a其一般形式如下:x0dx0a[section1] // 配置节x0dx0a//键名 //键值x0dx0akeyword1 = valuelx0dx0akeyword2 = value2x0dx0a??x0dx0a[section2]x0dx0akeyword3 = value3x0dx0akeyword4 = value4x0dx0a在Windows系统中,INI文件是很多,最重要的就是”System.ini”、”System32.ini”和”Win.ini”。该文件主要存放用户所做的选择以及系统的各种参数。用户可以通过修改INI文件,来改变应用程序和系统的很多配置。但自从Windows 95的退出,在Windows系统中引入了注册表的概念,INI文件在Windows系统的地位就开始不断下滑,这是因为注册表的独特优点,使应用程序和系统都把许多参数和初始化信息放进了注册表中。以及XML文件的国际标准化给INI文件又一次打击。x0dx0a但在某些场合,INI文件还拥有其不可替代的地位。比如绿色软件的规定就是不向注册表和系统中填入新东西。对于软件需要储存的信息就需要存入到文件中了。XML虽然兼容性比较好,但对于仅仅保存几个自定义参数而言就显得大材小用了。这是就可以选择使用快速简单的储存方式:INI文件。x0dx0a本文就来探讨一下C#是如何对INI进行读写操作。x0dx0a主要思路是调用Win32 API。x0dx0a1.引入命名空间x0dx0ausingSystem.Runtime.InteropServices;x0dx0a2.声明(把一个Win32 API函数转成C#函数)x0dx0a//声明INI文件的写操作函数 WritePrivateProfileString()x0dx0a[DllImport(“kernel32”)]x0dx0aprivate static extern longWritePrivateProfileString(string section, string key, string val, stringfilePath);x0dx0a//声明INI文件的读操作函数 GetPrivateProfileString()x0dx0a[DllImport(“kernel32”)]x0dx0aprivate static extern intGetPrivateProfileString(string section, string key, string def, StringBuilderretVal, int size, string filePath);x0dx0a3.函数x0dx0apublic void Writue(string section,string key, string value)x0dx0a{x0dx0a// section=配置节,key=键名,value=键值,path=路径(section,key, value, sPath);x0dx0a}x0dx0apublic string ReadValue(stringsection, string key)x0dx0a{x0dx0a// 每次从ini中读取多少字节x0dx0aSystem.Text.StringBuilder temp =new System.Text.StringBuilder(255);x0dx0a// section=配置节,key=键名,temp=上面,path=路径x0dx0aGetPrivateProfileString(section,key, “”, temp, 255, sPath);x0dx0areturntemp.ToString(); //注意类型的转换x0dx0a}x0dx0a到此基本功能已经实现了。下面我们将所有的代码重新整合一下:x0dx0anamespace Library.Filex0dx0a{x0dx0apublic class Inix0dx0a{x0dx0a// 声明INI文件的写操作函数 WritePrivateProfileString()x0dx0a[System.Runtime.InteropServices.DllImport(“kernel32”)]x0dx0aprivate static extern longWritePrivateProfileString(string section, string key, string val, stringfilePath);x0dx0a// 声明INI文件的读操作函数 GetPrivateProfileString()x0dx0a[System.Runtime.InteropServices.DllImport(“kernel32”)]x0dx0aprivate static extern intGetPrivateProfileString(string section, string key, string def,System.Text.StringBuilder retVal, int size, string filePath);x0dx0aprivate string sPath = null;x0dx0apublic Ini(string path)x0dx0a{x0dx0athis.sPath = path;x0dx0a}x0dx0apublic void Writue(string section,string key, string value)x0dx0a{x0dx0a// section=配置节,key=键名,value=键值,path=路径(section,key, value, sPath);x0dx0a}x0dx0apublic string ReadValue(stringsection, string key)x0dx0a{x0dx0a// 每次从ini中读取多少字节x0dx0aSystem.Text.StringBuilder temp =new System.Text.StringBuilder(255);x0dx0a// section=配置节,key=键名,temp=上面,path=路径x0dx0aGetPrivateProfileString(section,key, “”, temp, 255, sPath);x0dx0areturn temp.ToString();x0dx0a}x0dx0a}x0dx0a}x0dx0a开始调用函数。x0dx0a// 写入inix0dx0aIni ini = newIni(“C:/config.ini”);x0dx0aini.Writue(“Setting”,”key1″, “HELLO WORLD!”);x0dx0aini.Writue(“Setting”,”key2″, “HELLO CHINA!”);x0dx0a// 读取inix0dx0aIni ini = newIni(“C:/config.ini”);x0dx0astring str1 =ini.ReadValue(“Setting”, “key1”);x0dx0aMessageBox.Show(str1);x0dx0a二,在一些小的应用中,有时候不需要使用数据困这样大规模的数据管理工具,也很少进行数据的查询、修改等操作,而仅用文件来存储数据。这时就需要使用。net中的文件操作对象,如file、streamReader、streamWriter等。x0dx0a1,使用File对象操作文件x0dx0aSystem.IO.File类提供了一系类的静态办法,完成对晚间的常用操作,如新建、删除、拷贝、移动等x0dx0a2,使用StreamWriter写入文件x0dx0a在System.IO空间中定义了一个文件写入器对象StreamWriter,使用它可以以一种特定的编码向输出流中(Stream)写入字符。x0dx0a3,使用SteamReader读取文件x0dx0a与streamWrite对应

⑹ 用C语言读取一个文件中的内容,如何对不同的行进行解析,比如是配置文件

很简单的 配置文件 微软有抓们的一套解析函数 INI文件是Windows系统中一类比较重要的文件,通常用来存放系统或者应用程序的配置信息,以方便系统或者应用 程序在初始化时再次读入。比如Windows系统中的配置文件win.ini和system.ini,它们就主要存放系统启动或用户登陆时的系统信息。这 项功能在方便了系统配置的同时,也为非法程序的自动运行提供了可乘之机。显然,这类文件的重要性应该引起我们的重视。但是对于这样的ini文件的读写操作 却与普通文本文件有着种种的不同,尤其体现在编程实现上。笔者曾经尝试用手动更改的方法在文件中加入一些项,使得自己的程序能够在初始化时自动运行,但是 却没有成功,最后还是藉由编程的方法来实现了。这里主要涉及到一些API函数,而这些函数又往往不被人们所熟知,本文的任务就是在介绍这些函数的同时,用 简单的程序作了示例,下面我们言归正传。先来看几个往配置文件中写入信息的函数:(1)WritePrivateProfileSection()用来在ini文件中直接向指定区域写入键和值的信息,其原型如下:BOOL WritePrivateProfileSection(LPCTSTR lpAppName, // 指向指定字段的字符串LPCTSTR lpString, // 指向要写入的键与值字符串LPCTSTR lpFileName // 指向文件名称字符串,如果不包含完整路径,则在windows目录下创建);用法示例:WritePrivateProfileSection(_T(“windows”),_T(“load=c:\\winnt\\notepad.exe”),_T(“c:\\winnt\\win.ini”));(2)WritePrivateProfileString()与上一个函数的不同点在于其将键和值分开了,原型如下:BOOL WritePrivateProfileString(LPCTSTR lpAppName, // 指向指定字段的字符串LPCTSTR lpKeyName, // 指向指定键的字符串LPCTSTR lpString, // 指向指定值的字符串LPCTSTR lpFileName // 指向文件名称字符串);用法示例:WritePrivateProfileString(_T(“windows”),_T(load”)_T(“c:\\winnt\\notepad.exe”),_T(“c:\\winnt\\win.ini”));(3)WritePrivateProfileStruct()与前面两个的不同在于文件尾有校验和,原型如下:BOOL WritePrivateProfileStruct(LPCTSTR lpszSection, //指向指定字段的字符串LPCTSTR lpszKey, //指向指定键的字符串LPVOID lpStruct, //指向存放要加入的数据的缓冲区,如果为NULL,则删除键UINT uSizeStruct, //缓冲区大小,以字节为单位LPCTSTR szFile //以零结尾的文件名称字符串,如果为空,则向win.ini写入);用法示例:WritePrivateProfileStruct(_T(“windows”),_T(“load”),pBuffer,sizeof(pBuffer),_T(“c:\\winnt\\win.ini”));(4)还有两个函数,是专门用来向win.ini文件写入的,函数原型如下:BOOL WriteProfileSection(LPCTSTR lpAppName, //指向指定字段的字符串LPCTSTR lpString //指向指定值的字符串);BOOL WriteProfileString(LPCTSTR lpAppName, //指向指定字段的字符串LPCTSTR lpKeyName, //指向指定键的字符串LPCTSTR lpString //指向指定值的字符串);下面来看几个对应的从ini文件获取信息的API函数,上面已经说得很详细了,这里只说其中两个:DWORD GetPrivateProfileString(LPCTSTR lpAppName, //指向指定字段的字符串LPCTSTR lpKeyName, //指向键的字符串LPCTSTR lpDefault, //如果INI文件中没有前两个参数指定的字段名或键名,则将此值赋给变量LPTSTR lpReturnedString, //存放INI文件中值的目的缓存区DWORD nSize, //目的缓冲区的大小,以字节为单位LPCTSTR lpFileName //指向INI文件名称的字符串); UINT GetPrivateProfileInt(LPCTSTR lpAppName, //指向指定字段的字符串LPCTSTR lpKeyName, //指向键的字符串INT nDefault, //如果INI文件中没有前两个参数指定的字段名或键名,则将此值赋给变量LPCTSTR lpFileName //指向INI文件名称的字符串);程序示例1: 我们在这里建立了一个应用程序“App Name”,并且使用了一个INI文件“appname.ini”,在此INI文件中,我们写入如下内容:[Section1] FirstKey = It all worked out okay. SecondKey = By golly, it works. ThirdKey = Another test. 代码分析如下:#include <stdio.h> #include <windows.h>//主函数main() { //定义局部CHAR inBuf[80]; HKEY hKey1, hKey2; DWORD dwDisposition; LONG lRetCode; // 试图创建INI文件的键值lRetCode = RegCreateKeyEx ( HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT \\CurrentVersion\\IniFileMapping\\appname.ini", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey1, &dwDisposition); //判断是否出错if (lRetCode != ERROR_SUCCESS){ printf ("Error in creating appname.ini key\n"); return (0) ; } //试图设置一个节区的值lRetCode = RegSetValueEx ( hKey1, "Section1", 0, REG_SZ, "USR:App Name\\Section1", 20); //判断是否出错if (lRetCode != ERROR_SUCCESS) { printf ( "Error in setting Section1 value\n"); return (0) ; } //试图创建一个应用名称键值lRetCode = RegCreateKeyEx ( HKEY_CURRENT_USER, "App Name", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey2, &dwDisposition); //判断是否出错if (lRetCode != ERROR_SUCCESS) { printf ("Error in creating App Name key\n"); return (0) ; }//强制系统重新读取映射区的内容到共享内存中,以便于将来对应用程序的调用可//以找到它,而不需要重新启动系统 WritePrivateProfileStringW( NULL, NULL, NULL, L"appname.ini" ); //向INI文件中添加一些键值 WritePrivateProfileString ("Section1", "FirstKey", "It all worked out okay.", "appname.ini"); WritePrivateProfileString ("Section1", "SecondKey", "By golly, it works.", "appname.ini"); WritePrivateProfileSection ("Section1", "ThirdKey = Another Test.", "appname.ini"); //测试一下添加的正确性GetPrivateProfileString ("Section1", "FirstKey", "Bogus Value: Get didn't work", inBuf, 80, "appname.ini"); printf ("%s", inBuf); return(0); }程序示例2:通过修改win.ini中的字段[windows]中的键load或run,或者是为system.ini中的字段[boot]中的键 shell增加值,可以达到设置程序自动运行的目的。假设我们要自动运行notepad.exe,修改后的win.ini或system.ini文件象这 样就可以:win.ini[windows]load=c:\winnt\notepad.exerun=c:\winnt\notepad.exesystem.ini[boot]shell=c:\winnt\explorer.exe c:\winnt\notepad.exe注意:system.ini文件的修改要特别注意,如果你单纯改成shell=c:\winnt\notepad.exe,则不能首先运行 explorer.exe,很明显你将看不到桌面和任务栏,呵呵,笔者在做实验时就曾因为粗心造成了这样的后果,不过不用害怕,只要你用我们下面提供的程 序,将它修改过来就可以了,默认时,系统在system.ini中的[boot]下是shell=c:\winnt\explorer.exe。很多非法 程序就是通过修改这两个文件来达到自启动的目的的。下面这个程序可以在附书光盘中找到,名称为“AutoPlay”,使用VC++6.0写成,核心程序源代码如下:void CAutoRunDlg::OnBrowse() {//只浏览exe文件CfileDialog fileDlg(TRUE,_T("EXE"),_T("*.exe"),OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,(_T("Executable Files (*.exe) |*.exe ||")));//显示打开文件的对话框//当操作者选择OK时,程序取得选择文件的全路径名(包括文件的路径及文件名称),并将相应的数值传输给相关的控件变量。if(fileDlg.DoModal()==IDOK){ m_strFileName=fileDlg.GetPathName();//向将变量中的数值传输给控件显示出来。 UpdateData(FALSE);} }void CAutoRunDlg::OnApply() {//更新数据UpdateData(TRUE); //写入ini文件LPCTSTR filename; filename=m_strFileName; WritePrivateProfileString(_T("windows"),_T("load"),filename,_T("c:\\winnt\\win.ini"));}您如果要更改system.ini,可以将WritePrivateProfileString(_T("windows"),_T("load"),filename,_T("c:\\winnt\\win.ini"));改为 WritePrivateProfileString(_T("boot"),_T("shell"),filename,_T("c:\\winnt \\system.ini"));并且在输入文件名时输入c:\winnt\explorer.exe c:\winnt\notepad.exe。写到这里,本文的意图基本达到,如果您可以把某些代码亲自实现,相信读者会有比较大的收获。

⑺ c中读取配置文件一般是怎么写的

我是这么做的,比如 ini 里以 #注释,以=表示赋值## Note #aaa=bbb我从ini里一行一行读出来,如果第一回个字母是答#,就忽略否则就从 line_of_file 里查找 “=”字符,(去掉行末'\n'换行符)=之前的就是参数名,=之后的就是参数值(去掉空格,tab)(用strncpy)

⑻ C语言如何读取指定路径下的所有指定格式的文件

用C语言读取目录中的文件名的方法:1、如果是在window环境下,可以用一下方法:使用stdlib.h头文件声明的system()函数_CRTIMP int __cdecl system (const char*);system("dir c:\ /a:h /b > c:\dir.txt");调用系统命令dir,把c:目录下文件列表写入文件dir.txt中2、使用dirent.h头文件中声明的opendir(),readdir()函数;

intmain(intargc,char*argv[]){DIR*directory_pointer;structdirent*entry;if((directory_pointer=opendir("d:\XL"))==NULL)printf("Erroropening
");else{while((entry=readdir(directory_pointer))!=NULL){printf("%s
",entry->d_name);}closedir(directory_pointer);}system("PAUSE");return0;}

3、如果没有dirent.h,可以使用io.h头文件中声明的_findfirst(),_findnext()函数;示例代码:

intmain(intargc,char*argv[]){longfile;struct_finddata_tfind;_chdir("d:\");if((file=_findfirst("*.*",&find))==-1L){printf("空白!
");exit(0);}printf("%s
",find.name);while(_findnext(file,&find)==0){printf("%s
",find.name);}_findclose(file);system("PAUSE");return0;}

⑼ 如何在VC中实现配置文件(ini)的读写

配置文件在重要性不言而喻,在我们常用的软件中经常可以看到它的身影,它提供了程序初始化过程中一些常用的参数,并且可以手动的修改这些参数,因此使用起来非常的方便。常见的配置文件为*.ini文件。[小节名]关键字=值关键字=值……MFC为用户读取ini文件提供了几个函数,其中常用的几个函数分别如下:读取信息:GetPrivateProfileString和GetPrivateProfileInt写入信息:WritePrivateProfileString运用这几个函数就可以满足常用的对字符串和整数的读写操作了。为了体现MFC的封装性以及方便使用,我们可以定义一个接口,即一个纯虚类。所有的方法都由这个接口继承而来。我们将这个纯虚类命名为CCfgFile,之后我们从这个纯虚类中继承一个类(CIniFile)用来实现对ini文件的读取。以后若是需要一些更高级的方法可以再从CCfgFile继承出其他的类来实现。这样我们就可以利用CIniFile类中定义的函数来操纵ini文件了。在程序中我们需要操作ini文件中一些常用的配置参数读写,我们可以定义一个参数类来实现,如CParam这里需要注意的是在程序中我们可能在很多地方都要实现配置参数的读写,我们不能在每个要使用的地方都通过new关键字来创建一个CParam对象。原因你懂的,呵呵!那么我们可以通过定义CParam的一个静态成员来实现,这个静态成员通过一个静态的成员函数来获取。

⑽ C语言,如何读入一个10M左右的配置文件到程序中 配置文件的内容是程序中定义的某个结构体的结构内容。

要读入的文件内容为: TERMSTRU ermstru[]= { { "111111", "EA5U" }, { "222222", "EA5U" }, { "333333", "EA5U" }, { "444444", "DHTD" }, { "155555", "DHLO" }, } 大概上万行 本来这个内容是在程序体里面的,但是需要经常修改程序内容,所以我想把它变成一个配置文件,每次执行程序的时候自动读入到程序中。 恳请各位高手援助,最好写出程序,万分感谢!!!


赞 (0)