针对linux下的程序,有两个路径: 1>运行程序的路径; 2>可执行文件所在的路径

例如:

如果我在/home/yongchao下执行

$ ./temp/test    那么 运行程序的路径是:/home/yongchao   而可执行文件所在的路径是/home/yongchao/test

执行结果:

ps: 还有一个通过相对路径来寻找绝对路径的程序

 #include<limits.h>
#include<stdlib.h>
#include<string>
#include<iostream>
using namespace std; int main(int argc, char** argv)
{
char relative_path[] = "./";
char absolute_path[] = {};
if ( NULL == realpath(relative_path, absolute_path) )
{
cout<<"resolve path error"<<endl;
return ;
} cout<<"the absolute path : "<<absolute_path<<endl;
return ;
}
执行结果:


最新文章

  1. 使用 Box2D 做一个 JansenWalker 机器人
  2. MyBatis代码自动生成(利用eclipse插件)
  3. C++11 lambda的理解
  4. mysql 存储过程 游标的使用
  5. js反序列化时间
  6. 自定义QT事件
  7. dp hdu-4433 locker
  8. [转载]Access to the path &#39;&#39; is denied.解决方案
  9. struts-json
  10. 逻辑(if)、关系、数字、条件运算符
  11. 如何在Cocos2D游戏中实现A*寻路算法(四)
  12. java:合并两个排序的链表(递归+非递归)
  13. liunx一键安装禅道
  14. node.js+ react + redux 环境搭建
  15. js实现页面与页面之间传值的几种方法优劣
  16. ASP.NET 简介
  17. 【LeetCode题解】24_两两交换链表中的节点(Swap-Nodes-in-Pairs)
  18. 解决mysql日志显示时间和“Got an error reading communication packets” 问题
  19. 廖雪峰Java1-2Java程序基础-3整数运算
  20. alphe4

热门文章

  1. OpenWRT加入 crontab开机默认运行
  2. Vim 快捷键整理
  3. [Javascript] Adding Shapes to Maps with Leaflet and GeoJSON
  4. Open quote is expected for attribute &quot;{1}&quot; associated with an element type &quot;name&quot;.
  5. ThinkPHP函数详解:cookie方法
  6. export命令和import命令 详解
  7. Unity3D 之防止刚体碰撞导致旋转
  8. Spring、struts、webwork2三者MVC的比较
  9. 20160409 javaweb 数据库连接池
  10. 在VM虚拟机中安装centos7