路径的处理方法,望兄弟们帮忙,在线等。

yingzhi9 2011-05-28 10:27:35
//#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下去不能正确登陆。
...全文
145 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
ddweidong 2013-01-25
  • 打赏
  • 举报
回复
#pragma comment(lib,"Shlwapi.lib")
解决问题
rendao0563 2012-05-29
  • 打赏
  • 举报
回复
GetCurrentDirectory 删掉.
moon_cat 2012-05-29
  • 打赏
  • 举报
回复
#pragma import ....
或者loadlibrary () ,
或者上面的方法
qingkongxiaoyang 2012-05-28
  • 打赏
  • 举报
回复
没引用lib的关系,我使用的是VC6.0,也是遇到这个问题。
在setting中-〉Link下设置Shlwapi.lib 即可。
VS2010还真不知道怎么设置?我没怎么用过。
你可以参考一下,希望对你有帮助。
yingzhi9 2011-05-28
  • 打赏
  • 举报
回复
PathRemoveFileSpec我用这个函数为什么不行呀,代替GetCurrentDirectory(sizeof(chaBuf),chaBuf);后出错
1>1.obj : error LNK2001: 无法解析的外部符号 __imp__PathRemoveFileSpecA@4
1>G:\c\sheji_1\Debug\sheji_1.exe : fatal error LNK1120: 1 个无法解析的外部命令

求帮助。是不是缺dll文件呀,我用的是vs2010

70,037

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧