• 写入
 WritePrivateProfileStringA("hello money", infx[i].name, money, "1.ini");
  • 按照字符串读取

     GetPrivateProfileStringA("hello money", infx[i].name, "NULL", money, , "1.ini");

    函数原型:

     GetPrivateProfileStringA(
    _In_opt_ LPCSTR lpAppName,
    _In_opt_ LPCSTR lpKeyName,
    _In_opt_ LPCSTR lpDefault,
    _Out_writes_to_opt_(nSize, return +) LPSTR lpReturnedString,
    _In_ DWORD nSize,
    _In_opt_ LPCSTR lpFileName
    );
     GetPrivateProfileIntA(
    _In_ LPCSTR lpAppName,
    _In_ LPCSTR lpKeyName,
    _In_ INT nDefault,
    _In_opt_ LPCSTR lpFileName
    );

    按照int类型读取,结果在返回值

     int  num=;
    num=GetPrivateProfileIntA("hello money", infx[i].name, num, "1.ini");//结果在返回值

完整代码

 #define  _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include <Windows.h> //创建结构体写入ini
struct info
{
char name[];
int money; }; void main()
{
//初始化
struct info infx[] = { { "xiaowang", }, { "xiaoli", }, { "xiaosun", }, { "xiaozhou", }, { "xiaobin", } };
//写入ini文件
//for (int i = 0; i < 5;i++)
//{
// char money[40] = { 0 };
// //把int类型转换为char*类型
// _itoa(infx[i].money, money, 10);
// //不指定路径,会写入系统目录
// WritePrivateProfileStringA("hello money", infx[i].name, money, "F:\\智锋\\20150526\\ini文件\\ini文件\\1.ini");
//} for (int i = ; i < ;i++)
{
//根据姓名读取到字符串
//char money[40] = { 0 };
//GetPrivateProfileStringA("hello money", infx[i].name, "NULL", money, 40, "F:\\智锋\\20150526\\ini文件\\ini文件\\1.ini");
//printf("\n%s %s",infx[i].name, money);
/*GetPrivateProfileStringA(
_In_opt_ LPCSTR lpAppName,
_In_opt_ LPCSTR lpKeyName,
_In_opt_ LPCSTR lpDefault,
_Out_writes_to_opt_(nSize, return +1) LPSTR lpReturnedString,
_In_ DWORD nSize,
_In_opt_ LPCSTR lpFileName
);*/
/* GetPrivateProfileIntA(
_In_ LPCSTR lpAppName,
_In_ LPCSTR lpKeyName,
_In_ INT nDefault,
_In_opt_ LPCSTR lpFileName
);*/
//根据姓名读取到int类型中
int num=;
num = GetPrivateProfileIntA("hello money", infx[i].name, num, "1.ini");
printf("%d\n", num);
}
system("pause");
}

91.生成ini文件并写入和读取ini文件的更多相关文章

  1. INI文件的写入与读取

    INI文件的写入与读取 [节名]         '[]中的节名对应此API的第一参数 Name=内容      'Nmae对应此API的第二参数 API的第三参数是没有取到匹配内容时返回的字符串; ...

  2. 装饰者模式的学习(c#) EF SaveChanges() 报错(转载) C# 四舍五入 保留两位小数(转载) DataGridView样式生成器使用说明 MSSQL如何将查询结果拼接成字符串 快递查询 C# 通过smtp直接发送邮件 C# 带参访问接口,WebClient方式 C# 发送手机短信 文件 日志 写入 与读取

    装饰者模式的学习(c#) 案例转自https://www.cnblogs.com/stonefeng/p/5679638.html //主体基类 using System;using System.C ...

  3. C# winform写入和读取TXT文件

    C# winform写入和读取TXT文件 string str;            str=this.textBox1.Text;            StreamWriter sw = new ...

  4. winform 写入和读取TXT文件

    C# winform写入和读取TXT文件 string str; str=this.textBox1.Text; StreamWriter sw = new StreamWriter(Applicat ...

  5. 在C#程序中,创建、写入、读取XML文件的方法

    一.在C#程序中,创建.写入.读取XML文件的方法 1.创建和读取XML文件的方法,Values为需要写入的值 private void WriteXML(string Values) { //保存的 ...

  6. [转]VC++中对文件的写入和读取

    本文转自:http://blog.csdn.net/fanghb_1984/article/details/7425705 本文介绍两种方法对文件进行读取和写入操作:1.采用fstream类:2.采用 ...

  7. java的bio和nio写入及读取txt文件

    一.bio的写入及读取 1.采用bio之BufferedWriter 写入文件 public static void main(String[] args) throws IOException { ...

  8. android文件的写入与读取---简单的文本读写context.openFileInput() context.openFileOutput()

      最终效果图,点击save会保存到文件中,点击show会从文件中读取出内容并显示. main.xml <?xml version="1.0" encoding=" ...

  9. 第十七章,txt文件的写入和读取数据结合练习(C++)

    #include <iostream> #include <fstream> int main(int argc, char** argv) { std::string str ...

随机推荐

  1. ASP.net Web API允许跨域访问解决办法

    来源 http://blog.csdn.net/wxg_kingwolfmsncn/article/details/48545099 遇到此跨域访问问题,解决办法如下:   方法一:   1. 在we ...

  2. Inter-process Communication (IPC)

    For Developers‎ > ‎Design Documents‎ > ‎ Inter-process Communication (IPC) 目录 1 Overview 1.1 I ...

  3. highcharts中的x轴如何显示时分秒时间格式

    上一篇文章写道:三分钟上手Highcharts简易甘特图:https://www.jianshu.com/p/d669d451711b,在官方文档里面,x轴默认为年月日. 在项目需求中,x轴要表示24 ...

  4. CodeForcesGym 100502E Opening Ceremony

    Opening Ceremony Time Limit: 5000ms Memory Limit: 524288KB This problem will be judged on CodeForces ...

  5. PostgreSQL递归查询实现树状结构查询

    在Postgresql的使用过程中发现了一个非常有意思的功能,就是对于须要相似于树状结构的结果能够使用递归查询实现.比方说我们经常使用的公司部门这样的数据结构.一般我们设计表结构的时候都是相似以下的S ...

  6. pat(A) 1065. A+B and C (64bit) (java大数)

    代码: import java.util.*; import java.math.*; public class Main { public static void main(String args[ ...

  7. 转:关于ios 推送功能的终极解决

    刚刚做了一个使用推送功能的应用 遇到了一些问题整的很郁闷 搞了两天总算是弄明白了 特此分享给大家 本帖 主要是针对产品发布版本的一些问题 综合了网上一些资料根据自己实践写的 不过测试也可以看看 首先要 ...

  8. CRSF Defense Using Content Injection Support By ModSecurity

    The most advanced and imaginative use of the content injection feature is that devised byRyan C. Bar ...

  9. rtmp,rtsp,hLS区别

    流媒体协议一共三种:rtmp,rtsp,http live streaming(apple和adobe各一种)rtmp是adobe的,rtsp android native支持,http live s ...

  10. 项目融入mongoDB

    1.pom.xml导入jar包           <!-- mongoDB -->         <dependency>           <groupId> ...