读取含中文内容ini文件代码
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <cstring>
string outline_image_path;
LPCTSTR ini_path = "D:/cudaHygiene/image/带蓝芯弧形/带蓝芯弧形.ini";
//读取整型ini数据
int getInt(LPCTSTR lpKeyName, INT nDefault)
{
int value = GetPrivateProfileInt("Detection", lpKeyName, nDefault, ini_path);
return value;
}
//读取浮点型ini数据
double getDouble(LPCTSTR lpKeyName, LPCTSTR nDefault)
{
//读取字符型ini数据
char value[20];
GetPrivateProfileString("Detection", lpKeyName, nDefault, value, sizeof(value), ini_path);
//转为double型
return strtod(value, NULL);
}
void read_ini()
{
int model_flag = getInt("model_flag", 0);
int filter_flag = getInt("model_flag", 0);
int defect_distance = getInt("defect_distance", 1);
int defect_height = getInt("defect_height", 1);
int defect_width = getInt("defect_width", 1);
double Zoom_factor_x = getDouble("Zoom_factor_x", "1");;
double Zoom_factor_y = getDouble("Zoom_factor_y", "1");;
char file_path[200];
GetPrivateProfileStringA("Detection", "configuration_file_path ", "", file_path, sizeof(file_path), ini_path);;
//修改字符数组
strcpy_s(configuration_file_path, file_path);
GetPrivateProfileString("Detection", "outline_image_path", "", file_path, sizeof(file_path), ini_path);
//修改字符串
outline_image_path = file_path;
}
含中文内容的ini文件编码格式改为UTF-16LE(可打开文件,另存为,选择下方的编码格式),就可以读取中文内容了

该博客主要介绍了如何处理C++中读取包含中文内容的ini配置文件,重点是将文件编码转换为UTF-16LE以便正确解析中文字符。

被折叠的 条评论
为什么被折叠?



