本文整理汇总了C++中path::c_str方法的典型用法代码示例。如果您正苦于以下问题:C++ path::c_str方法的具体用法?C++ path::c_str怎么用?C++ path::c_str使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类path
的用法示例。
在下文中一共展示了path::c_str方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: __create_symlink
void __create_symlink(path const & from, path const & to, std::error_code *ec) {
if (::symlink(from.c_str(), to.c_str()) == -1)
set_or_throw(ec, "create_symlink", from, to);
else if (ec)
ec->clear();
}
示例2: fin
ConfigParser::ConfigParser(const path & configFile) :
m_configFilePath(configFile)
{
ifstream fin(configFile.c_str());
string configBuffer;
string buff;
if (fin.is_open())
{
while (fin.good())
{
getline(fin, buff);
// if this isn't just an empty line or a comment
if (buff[0] != '\0' && buff[0] != '#')
configBuffer += buff + '\n';
}
}
else
{
string errMsg = "Cannot read configuration file \"";
errMsg += configFile.c_str();
errMsg += '\"';
LogManager::getInstancePtr()->log(errMsg, LogManager::L_ERROR);
throw FSException(errMsg, __FILE__, __LINE__);
}
fin.close();
m_fsyncHomePath = getFsyncHomePath();
generatePairs(configBuffer);
}
示例3: copy
//------------------------------------------------------------------------------
void FileCopier::copy (path const& srcpath, path const& dstpath, path const& dsppath) {
// declare variables
long unsigned buf_count = 0;
long unsigned buf_trigger = bufs_per_update;
FileSize initialBytes = status.bytes;
// update status
status.fileTotal = file_size(srcpath);
status.srcPath = srcpath;
status.dstPath = dstpath;
status.dspPath = dsppath;
// open files
ifstream src(srcpath.c_str());
ofstream dst;
if (!safe_mode) dst.open(dstpath.c_str(), ios_base::out | ios_base::binary);
printStart(status);
while (src) {
if (buf_count++ == buf_trigger) {
buf_trigger += bufs_per_update;
FileSize newbytes = bufs_per_update * BUFSIZ;
status.bytes += newbytes;
status.fileBytes += newbytes;
printUpdate(status);
}
src.read(buf, BUFSIZ);
if (!safe_mode) dst.write(buf, src.gcount());
}
src.close();
if (!safe_mode) dst.close();
status.bytes = initialBytes + status.fileTotal;
}
示例4: rename
void rename(const path& from, const path& to, std::error_code& ec) noexcept
{
if (::rename(from.c_str(), to.c_str())) {
ec = {errno, std::system_category()};
} else {
ec.clear();
}
}
示例5: __last_write_time
void __last_write_time(const path& p, file_time_type new_time,
std::error_code *ec)
{
using namespace std::chrono;
std::error_code m_ec;
// We can use the presence of UTIME_OMIT to detect platforms that do not
// provide utimensat.
#if !defined(UTIME_OMIT)
// This implementation has a race condition between determining the
// last access time and attempting to set it to the same value using
// ::utimes
struct ::stat st;
file_status fst = detail::posix_stat(p, st, &m_ec);
if (m_ec && !status_known(fst)) {
set_or_throw(m_ec, ec, "last_write_time", p);
return;
}
struct ::timeval tbuf[2];
tbuf[0].tv_sec = st.st_atime;
tbuf[0].tv_usec = 0;
const bool overflowed = !detail::set_times_checked<microseconds>(
&tbuf[1].tv_sec, &tbuf[1].tv_usec, new_time);
if (overflowed) {
set_or_throw(make_error_code(errc::invalid_argument), ec,
"last_write_time", p);
return;
}
if (::utimes(p.c_str(), tbuf) == -1) {
m_ec = detail::capture_errno();
}
#else
struct ::timespec tbuf[2];
tbuf[0].tv_sec = 0;
tbuf[0].tv_nsec = UTIME_OMIT;
const bool overflowed = !detail::set_times_checked<nanoseconds>(
&tbuf[1].tv_sec, &tbuf[1].tv_nsec, new_time);
if (overflowed) {
set_or_throw(make_error_code(errc::invalid_argument),
ec, "last_write_time", p);
return;
}
if (::utimensat(AT_FDCWD, p.c_str(), tbuf, 0) == -1) {
m_ec = detail::capture_errno();
}
#endif
if (m_ec)
set_or_throw(m_ec, ec, "last_write_time", p);
else if (ec)
ec->clear();
}
示例6: rename
//------------------------------------------------------------------------------
void rename(const path &op, const path &np)
{
const int r = ::rename(op.c_str(), np.c_str());
if(r != 0)
{
n_throw(system::system_error)
<< ei_msg_c("rename() failed.")
<< ei_path(op)
<< system::ei_error_code(system::error_code(
errno, system::system_category()));
}
}
示例7: equivalent
bool equivalent(const path& p1, const path& p2, std::error_code& ec) noexcept
{
struct stat st1;
struct stat st2;
if (::stat(p1.c_str(), &st1) || ::stat(p2.c_str(), &st2)) {
ec = {errno, std::system_category()};
return false;
} else {
ec.clear();
return st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino;
}
}
示例8: __last_write_time
void __last_write_time(const path& p, file_time_type new_time,
std::error_code *ec)
{
using namespace std::chrono;
std::error_code m_ec;
#if !defined(_LIBCXX_USE_UTIMENSAT)
// This implementation has a race condition between determining the
// last access time and attempting to set it to the same value using
// ::utimes
struct ::stat st;
file_status fst = detail::posix_stat(p, st, &m_ec);
if (m_ec && !status_known(fst)) {
set_or_throw(m_ec, ec, "last_write_time", p);
return;
}
auto atime = detail::extract_atime(st);
struct ::timeval tbuf[2];
tbuf[0].tv_sec = atime.tv_sec;
tbuf[0].tv_usec = duration_cast<microseconds>(nanoseconds(atime.tv_nsec)).count();
const bool overflowed = !FSTime::set_times_checked<microseconds>(
&tbuf[1].tv_sec, &tbuf[1].tv_usec, new_time);
if (overflowed) {
set_or_throw(make_error_code(errc::invalid_argument), ec,
"last_write_time", p);
return;
}
if (::utimes(p.c_str(), tbuf) == -1) {
m_ec = detail::capture_errno();
}
#else
struct ::timespec tbuf[2];
tbuf[0].tv_sec = 0;
tbuf[0].tv_nsec = UTIME_OMIT;
const bool overflowed = !FSTime::set_times_checked<nanoseconds>(
&tbuf[1].tv_sec, &tbuf[1].tv_nsec, new_time);
if (overflowed) {
set_or_throw(make_error_code(errc::invalid_argument),
ec, "last_write_time", p);
return;
}
if (::utimensat(AT_FDCWD, p.c_str(), tbuf, 0) == -1) {
m_ec = detail::capture_errno();
}
#endif
if (m_ec)
set_or_throw(m_ec, ec, "last_write_time", p);
else if (ec)
ec->clear();
}
示例9: create_directory
bool filesys::create_directory(const path & p)
{
/*
*/
# if OS_WINDOWS
return CreateDirectory(p.c_str(), 0) != 0;
# elif OS_LINUX
int32 stat = mkdir(p.c_str(), 777);
return stat != 0;
# else
# endif
return false;
}
示例10: hdl
filesys::DirectoryIterator::DirectoryIterator(const path & p, const path& filter /* = "*.*"*/) :
hdl(nullptr),
i(0), n(0),
current(""), basePath("")
{
/*
WIN32_FIND_DATA ffd;
path p2 = filesys::concat(p, filter);
basePath = p;
hdl = FindFirstFile(p2.c_str(), &ffd);
if (hdl == INVALID_HANDLE_VALUE)
hdl = nullptr;
current = filesys::concat(basePath,path(ffd.cFileName));
if (path(ffd.cFileName) == "." || path(ffd.cFileName) == "..")
operator ++();
*/
# if OS_WINDOWS || OS_LINUX
basePath = p;
i = 0;
struct dirent **nameList = nullptr;
n = scandir(p.c_str(),&nameList,filter_dirEntry, alphasort);
if(n <= 0) {
hdl = nullptr;
n = 0;
return;
}
hdl = (void*)nameList;
current = filesys::concat(basePath,filesys::path(nameList[i]->d_name));
free(nameList[i++]);
# else
# endif
}
示例11: cfg_file
HashTable<string,std::vector<string> > read_configuration_file(const path cfg_path)
{
assert(is_regular_file(cfg_path));
auto hash_table=HashTable<std::string,std::vector<std::string>>();
std::ifstream cfg_file(cfg_path.c_str());
std::string line;
std::vector<std::string> parts;
while ( std::getline(cfg_file,line) )
{
split( parts,line,boost::is_any_of("=") );
switch (parts.size())
{
case 0 :
throw std::string("Malformed configuration file : "+line);
break;
case 1 : // probably empty line
break;
case 2 :
std::string key=parts[0];
std::string value=parts[1];
if (!hash_table.isKey(key))
{
hash_table[key]=std::vector<std::string>();
}
hash_table[key].push_back(value);
break;
}
}
return hash_table;
}
示例12: Open
OPENPSTD_SHARED_EXPORT void PSTDFileAccess::Open(path filename)
{
boost::unique_lock<boost::recursive_mutex> m_lock(*this->mutex);
this->realPath = path(filename.c_str());
this->d = PSTDFile::Open(this->realPath);
this->Change();
}
示例13: getEntryFromFasta
/**
* Finds a particular fasta header in a fasta file and returns the associated sequence
**/
static int getEntryFromFasta(const path& fasta_path, const string& header, string& sequence)
{
// Setup stream to sequence file and check all is well
std::ifstream inputStream (fasta_path.c_str());
if (!inputStream.is_open())
{
std::cerr << "ERROR: Could not open the sequence file: " << fasta_path << endl;
return 0;
}
string id;
string seq;
// Read a record
while(inputStream.good() && readRecord(inputStream, id, seq) == 0)
{
stringstream ssHeader;
ssHeader << id;
if (header.compare(ssHeader.str()) == 0)
{
inputStream.close();
sequence = seq;
return 0;
}
seq.clear();
}
inputStream.close();
return -1;
}
示例14: absolute
path absolute(const path& filename)
{
if ( !filename.empty() )
{
#if (( defined( _POSIX_VERSION ) && _POSIX_VERSION >= 200809l ) || defined( __GLIBC__ ))
// Preferred - POSIX-2008 and glibc will allocate the path buffer
char* res = ::realpath(filename.c_str(), NULL);
if ( res )
{
path s = res;
::free(res);
return s;
}
#else
#ifdef _GNU_SOURCE
// Maybe we can rely on the GNU extension
char* res = ::canonicalize_file_name( filename.c_str() );
if ( res )
{
std::string s = res;
::free(res);
return s;
}
#elif ((( defined( _POSIX_VERSION ) && _POSIX_VERSION >= 200112L ) || ( defined( _XOPEN_VERSION ) && _XOPEN_VERSION >= 500 )) && defined( PATH_MAX ))
/// @todo PATH_MAX may be huge or -1, according to man pages for realpath
char resolved[PATH_MAX + 1];
char* res = ::realpath(filename.c_str(), resolved);
if ( res )
{
return resolved;
}
#else
#error "No way to get absolute file path!"
#endif // if 1
#endif // if ( defined( _POSIX_VERSION ) && _POSIX_VERSION >= 200809l )
}
return path();
}
示例15: resize_file
void resize_file(const path& p, uintmax_t size, std::error_code& ec) noexcept
{
if (::truncate(p.c_str(), static_cast<off_t>(size))) {
ec = {errno, std::system_category()};
} else {
ec.clear();
}
}