• 写入
 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. 关键字&标识符

    关键字:被Java语言赋予了特殊含义,用做专门用途的字符串(单词) 保留字: 标识符:凡是自己可以起名字的地方都叫标识符 命名的规则:(一定要遵守,不遵守就会报编译的错误)由26个英文字母大小写,0- ...

  2. linux 查看tomcat 实时日志

    进入tomcat下logs文件夹下,若没有Catalina.out文件先去启动服务在回到logs文件夹输入 tail -f catalina.out ,可看到实时日志

  3. 【Henu ACM Round#15 B】A and B and Compilation Errors

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 开3个map, 存在map里面: 然后迭代第一个和第二个map; 分别与第二个和第三个map比较就可以了 [代码] #include ...

  4. C# Arcgis Engine 捕捉功能实现

    namespace 捕捉 { public partial class Form1 : Form { private bool bCreateElement=true; ; ; private IEl ...

  5. poj2486--Apple Tree(树状dp)

    Apple Tree Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7789   Accepted: 2606 Descri ...

  6. Codeforces Round #262 (Div. 2) 题解

    A. Vasya and Socks time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  7. julia/pyplot 绘图加入标签和标题

    julia 调用matplotlib.pyplot 须要先using pycall 先安装pycall Pkg.add("PyCall") 然后吧. . . 上代码把:(应该是通俗 ...

  8. C语言之基本算法39—字符串经典操作

    //字符串概念! /* ================================================================== 题目:练习字符串的 1.输入输出      ...

  9. mysql_jdbc

    package com.lovo.day18_jdbc1; import java.sql.Connection; import java.sql.DriverManager; import java ...

  10. Android eclipse 提示java代码 快捷键

    1.提示java代码能够用ALT+/ 键就能够了(前提是你要把你须要的类或方法的首字母打出来).我添加的部分:仅仅要输入sysout,然后alt+/键就能够输出System.out.prinln(), ...