linux的getcwd和readlink的区别
2024-08-31 07:54:52
针对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 ;
}
执行结果:
最新文章
- 使用 Box2D 做一个 JansenWalker 机器人
- MyBatis代码自动生成(利用eclipse插件)
- C++11 lambda的理解
- mysql 存储过程 游标的使用
- js反序列化时间
- 自定义QT事件
- dp hdu-4433 locker
- [转载]Access to the path &#39;&#39; is denied.解决方案
- struts-json
- 逻辑(if)、关系、数字、条件运算符
- 如何在Cocos2D游戏中实现A*寻路算法(四)
- java:合并两个排序的链表(递归+非递归)
- liunx一键安装禅道
- node.js+ react + redux 环境搭建
- js实现页面与页面之间传值的几种方法优劣
- ASP.NET 简介
- 【LeetCode题解】24_两两交换链表中的节点(Swap-Nodes-in-Pairs)
- 解决mysql日志显示时间和“Got an error reading communication packets” 问题
- 廖雪峰Java1-2Java程序基础-3整数运算
- alphe4
热门文章
- OpenWRT加入 crontab开机默认运行
- Vim 快捷键整理
- [Javascript] Adding Shapes to Maps with Leaflet and GeoJSON
- Open quote is expected for attribute ";{1}"; associated with an element type ";name";.
- ThinkPHP函数详解:cookie方法
- export命令和import命令 详解
- Unity3D 之防止刚体碰撞导致旋转
- Spring、struts、webwork2三者MVC的比较
- 20160409 javaweb 数据库连接池
- 在VM虚拟机中安装centos7