路径的处理方法,望兄弟们帮忙,在线等。
//#include "stdafx.h"
#include <iostream>
#include<stdio.h>
#include<windows.h>
#include <Shlwapi.h>
using namespace std;
int main()
{
char UserName_Input[20];
char Password_Input[20];
char hello[]="\\UserInfo.ini";
char UserName[20];
char Password[20];
const int nBufSize= 512;
TCHAR chaBuf[nBufSize];
//TCHAR * lpStrPath=chaBuf;
if(!(GetModuleFileName(NULL,chaBuf,nBufSize)))
cout<<"GetModuleFileName error";
GetCurrentDirectory(sizeof(chaBuf),chaBuf);
strcat(chaBuf,hello);cout<<chaBuf<<endl;
cout<<"请输入用户名";
cin>>UserName_Input;
cout<<"input password";
cin>>Password_Input;
GetPrivateProfileString("UserInfo","UserName","",UserName,20,chaBuf);
GetPrivateProfileString("UserInfo","Password","",Password,20,chaBuf);
if(strcmp(UserName_Input,UserName)!=0||(strcmp(Password_Input,Password)!=0))
cout<<"登陆失败"<<endl;
else
cout<<"登陆成功"<<endl;
return 0;
}
昨天根据csdn一位热心人提醒,我用了GetModuleFileName处理路径问题,但是还是不行呀,我的UserInfo.ini的配置文件只能放在c盘根目录c:\UserInfo.ini才能登陆成功,而放在debug下去不能正确登陆。