相对路径生成绝对路径
2014-09-09 10:08
197 查看
#include "stdafx.h" #include <stack> #include <string> #include <iostream> using namespace std; void getWord(char* src,stack<string>&s) { string str=src; int index=0; while(1) { index=str.find_first_of("/"); if(index==0) { str=str.substr(index+1); continue; } else { string temp=str.substr(0,index); s.push(temp); str=str.substr(index+1); if(str.empty()) { break; } } } } void print(stack<string> s) { string str; while(!s.empty()) { string temp=s.top(); if(temp.find("..")!=-1) { s.pop(); s.pop(); } else { str="/"+temp+str; s.pop(); } } cout<<str.c_str()<<"/"<<endl; } int main() { char src[]="/home/news/../tmp/game/../"; stack<string> s; getWord(src,s); print(s); system("pause"); return 0; }
相关文章推荐
- CMake生成VS2010工程相对路径和绝对路径问题说明
- (转)JSP、Servlet中的相对路径和绝对路径(包括路径问题)
- 相对路径与绝对路径
- 相对路径和绝对路径
- php绝对路径与相对路径之间关系的的深入研究
- 【转】相对路径和绝对路径
- 关于函数由绝对路径转为相对路径
- C++中相对路径与绝对路径以及斜杠与反斜杠的区别
- java相对路径转换为绝对路径
- PHP相对路径和绝对路径常见处理方法
- Javaweb 绝对路径和相对路径-巧理解
- request请求获取相对路径和绝对路径
- 绝对路径和相对路径的区别
- (转)URI和URL区别以及相对路径和绝对路径的区别
- symfony2取得web目录绝对路径、相对路径、网址的函数是什么
- 相对路径和绝对路径
- C++中相对路径与绝对路径以及斜杠与反斜杠的区别
- 谈谈PHP中相对路径的问题与绝对路径的使用
- 相对路径和绝对路径的区别
- C++中相对路径与绝对路径以及斜杠与反斜杠的区别