您的位置:首页 > 编程语言 > PHP开发

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;
}


问题出现在注释部分,请高手指点。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: