Using STD lib
Check if element in the vector or list
T element = <instatiation>; std::vector<T> v; v=<initialization>; if (std::find(v.begin(), v.end(), element) != v.end()) {/*element is in v*/} else {/* is not there */}
Add element to the vector or list if it is not there
T element = <instatiation>; std::vector<T> v; v=<initialization>; if (std::find(v.begin(), v.end(), element) == v.end()) v.push_back(element);
Using boost
Iterate over files in the directory
#include <boost/filesystem.hpp> namespace fs = boost::filesystem; fs::path path = "/reg/d/psdm/CXI/cxi49012/xtc/e158-r0150-s00-c01.xtc"; fs::path dir = path.parent_path(); // i.e.: /reg/d/psdm/CXI/cxi49012/xtc typedef fs::directory_iterator dir_iter; for (dir_iter dit = dir_iter(dir); dit != dir_iter(); ++ dit) { std::cout << dit->path().stem().string() << "\n"; }
Other methods of fs::path
fs::path path = m_path; std::cout << "stem = " << path.stem().string() << "\n"; // e158-r0150-s00-c00 std::cout << "extension() = " << path.extension().string() << "\n"; // .xtc std::cout << "filename() = " << path.filename().string() << "\n"; // e158-r0150-s00-c00.xtc std::cout << "parent_path() = " << path.parent_path().string() << "\n"; // /reg/d/psdm/CXI/cxi49012/xtc
Overview
Content Tools