#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;
}
相对路径生成绝对路径
最新推荐文章于 2021-11-24 23:48:36 发布