GetPrivateProfileString的问题,获得的CString结构有问题,高手指点

来源:互联网 发布:大卫罗宾逊体测数据 编辑:程序博客网 时间:2024/04/30 07:29
// 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;}

问题出现在注释部分,请高手指点。
原创粉丝点击