codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
// Arun Saha, 2010-10-21 // http://stackoverflow.com/questions/3986056/get-the-path-difference-between-two-directories #include <string> #include <iostream> #include <algorithm> using namespace std; string mismatch_string( string const & a, string const & b ) { string::const_iterator longBegin, longEnd, shortBegin; if( a.length() >= b.length() ) { longBegin = a.begin(); longEnd = a.end(); shortBegin = b.begin(); } else { longBegin = b.begin(); longEnd = b.end(); shortBegin = a.begin(); } pair< string::const_iterator, string::const_iterator > mismatch_pair = mismatch( longBegin, longEnd, shortBegin ); return string( mismatch_pair.first, longEnd ); } int main() { string longer( "/home/benjamin/test/a/1" ); string shorter( "/home/benjamin/test/" ); cout << mismatch_string( longer, shorter ) << endl; cout << mismatch_string( shorter, longer ) << endl; }
Private
[
?
]
Run code
Submit