本文整理汇总了C++中path_t::string方法的典型用法代码示例。如果您正苦于以下问题:C++ path_t::string方法的具体用法?C++ path_t::string怎么用?C++ path_t::string使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类path_t
的用法示例。
在下文中一共展示了path_t::string方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: read
void read(std::basic_string<CharT>& buf, path_t const& path)
{
std::basic_string<char> buf_;
std::basic_ifstream<char> ifs(path.string());
ifs.imbue(std::locale(""));
if (!ifs) {
throw file_error("failed to open file " + path.string());
}
// get length
ifs.seekg(0, std::ios::end);
auto const len = ifs.tellg();
ifs.seekg(0, std::ios::beg);
buf_.resize(len);
ifs.read(&buf_[0], len);
buf = to<std::basic_string<CharT>>(buf_);
}
示例2: stat_filesize
uint64_t file_manager::stat_filesize(path_t const& p) const
{
std::ifstream fp(p.string().c_str(), std::ios_base::binary);
if (!fp.is_open() || !fp.good())
return 0;
uint64_t size = stat_filesize(fp);
fp.close();
return size;
}
示例3: fp
bool
downloader::fetch(string_t const& url, path_t const& path, string_t const& checksum, int* const retry_tally) const
{
// TODO: rethink about this, this really sounds like an external concern
for (int i = 0; i < retry_count_ + 1; ++i) {
bool fetch_successful;
if (!file_manager_.is_writable(path)) {
error() << "Download destination is un-writable: " << path;
return false;
}
std::ofstream fp(path.string().c_str(), std::ios_base::trunc | std::ios_base::binary);
if (retry_tally != nullptr) {
(*retry_tally) = i;
}
fetch_successful = fetch(url, fp);
fp.close();
if (fetch_successful) {
if (!file_manager_.is_readable(path)) {
return false; // this really shouldn't happen, but oh well
}
// validate integrity
hasher::digest_rc rc = config_.hasher->hex_digest(path);
if (rc == checksum) {
return true;
}
else {
warn()
<< "Downloaded file integrity mismatch: "
<< rc.digest << " vs " << checksum;
}
}
notice() << "Retry #" << i+1;
}
return false;
}
示例4: load_file
bool file_manager::load_file(path_t const& path, string_t& out_buf) const
{
return load_file(path.string(), out_buf);
}