GetPrivateProfileString的问题,获得的CString结构有问题,高手指点
2012-05-26 11:56
591 查看
// test.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include <afx.h> #include <fstream> #include <iostream> #include <string> #include <sstream> #include <math.h> using namespace std; void getSection(int *section, CString range); CString readINIStr(CString path, CString t_sGroupName, CString t_sRowName); int _tmain(int argc, _TCHAR* argv[]) { CString filePath; CString str; filePath = _T("d://paperINI.ini"); str = readINIStr(filePath, "paper", "range"); //cout << str << endl; int section[10]; //str.Format("%s",str); //如果不经过该部分的转换,出现乱码问题,说明getSection前后两个CString的结构不同 //str = "5 1 6"; //经测试getSection可以实现功能 getSection(section, str); //将字符串中数字分别放入section数组中,自己写的程序应该没问题 for(int i = 0; i < 10; i++) cout << section[i] << endl; system("pause"); return 0; } void getSection(int *section, CString range) { string str = range.GetBuffer(0); int num = 0; int len = str.length(); const char *temp1 = str.c_str(); const char *temp2 = temp1; len--; while(len) { string tempStr = ""; while(*temp2 != ' ' && len!=0) { tempStr += *temp2; temp2++; len--; } temp2++; temp1 = temp2; //获取整数 section[num] = atoi(tempStr.c_str()); num++; } //补全整数数组 for(num; num < 10; num++) { section[num] = section[0]; } } CString readINIStr(CString path, CString t_sGroupName, CString t_sRowName) { CString t_csGName = t_sGroupName; CString t_csRName = t_sRowName; CString strStudName; GetPrivateProfileString(t_csGName, t_csRName, _T("默认姓名"), strStudName.GetBuffer(MAX_PATH), MAX_PATH, path); return strStudName; }
问题出现在注释部分,请高手指点。
相关文章推荐
- GetPrivateProfileString的问题,获得的CString结构有问题,高手指点
- vista下GetPrivateProfileString的问题
- vb.net中使用GetPrivateProfileString访问INI文件,解决中文路径问题
- vb.net中使用GetPrivateProfileString访问INI文件,解决中文路径问题
- 关于getprivateprofilestring 读取 windows 文件夹下ini文件异常问题的探究
- 关于MFC在Unicode下使用GetPrivateProfileString的问题
- GetPrivateProfileString必须使用路径“.//xxxx.ini”
- 利用GetPrivateProfileString读取配置文件(.ini)
- 读取INI配置文件GetProfileString和GetPrivateProfileString参数说明和示例
- 利用GetPrivateProfileString读取配置文件(.ini)(
- GetPrivateProfileString
- 【转载】C++读写ini配置文件GetPrivateProfileString()&WritePrivateProfileString()
- MFC读取配置文件GetPrivateProfileString及获取绝对路径
- 易语言调用GetPrivateProfileStringA
- *.ini 文件 与 WritePrivateProfileString()和GetPrivateProfileString()
- VC:INI文件中键名数据的读写(GetPrivateProfileString())
- GetPrivateProfileString使用时的限制事项
- 利用GetPrivateProfileString/WritePrivateProfileString读写配置文件(.ini)
- getprivateprofilestring
- INI文件编程,WINAPI函数WritePrivateProfileString,GetPrivateProfileString