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

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

问题出现在注释部分,请高手指点。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值