C++ examples for File Stream:Directory
Combining Two Paths into a Single Path
#include <iostream> #include <string> using std::string; string pathAppend(const string& p1, const string& p2) { char sep = '/'; string tmp = p1;//from w w w . j a v a 2 s. c o m #ifdef _WIN32 sep = '\\'; #endif if (p1[p1.length()] != sep) { // Need to add a tmp += sep; // path separator return(tmp + p2); } else return(p1 + p2); } int main(int argc, char** argv) { string path = "c:/abc/def"; std::cout << "Appending somedir\\anotherdir is \"" << pathAppend(path, "somedir\\anotherdir") << "\"\n"; }