本文整理汇总了C++中std::iostream::clear方法的典型用法代码示例。如果您正苦于以下问题:C++ iostream::clear方法的具体用法?C++ iostream::clear怎么用?C++ iostream::clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::iostream
的用法示例。
在下文中一共展示了iostream::clear方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loadFile
void ResourceManager::loadFile(const std::string& fileName, std::iostream& out)
{
out.clear(std::ios::goodbit);
if(m_hasSearchPath) {
std::string fullPath = resolvePath(fileName);
PHYSFS_file* file = PHYSFS_openRead(fullPath.c_str());
if(!file) {
out.clear(std::ios::failbit);
stdext::throw_exception(stdext::format("failed to load file '%s': %s", fullPath.c_str(), PHYSFS_getLastError()));
} else {
int fileSize = PHYSFS_fileLength(file);
if(fileSize > 0) {
std::vector<char> buffer(fileSize);
PHYSFS_read(file, (void*)&buffer[0], 1, fileSize);
out.write(&buffer[0], fileSize);
} else
out.clear(std::ios::eofbit);
PHYSFS_close(file);
out.seekg(0, std::ios::beg);
}
} else {
std::ifstream fin(fileName);
if(!fin) {
out.clear(std::ios::failbit);
stdext::throw_exception(stdext::format("failed to load file '%s': %s", fileName.c_str(), PHYSFS_getLastError()));
} else {
out << fin.rdbuf();
}
}
}
示例2: on_connected
void on_connected(socket& /*socket*/, std::iostream& stream)
{
for (std::size_t keep_alive_count = config_.maximum_keep_alive_requests; keep_alive_count != 0; --keep_alive_count)
{
stream.exceptions(std::ios_base::badbit);
if (stream.peek() == EOF)
{
stream.clear();
break;
}
stream.exceptions(std::ios_base::eofbit | std::ios_base::failbit | std::ios_base::badbit);
http_server_context context(stream, config_);
http_request& req = context.request();
http_response& res = context.response();
bool head = false;
bool keep_alive = false;
try
{
context.read_headers();
switch (req.get_method())
{
case http_method::head:
head = true;
break;
case http_method::get:
case http_method::post:
break;
default:
BOOST_THROW_EXCEPTION(http_exception(http_status_code::method_not_allowed));
}
if (req.is_connection_keep_alive())
{
res.set_keep_alive_requests(keep_alive_count);
keep_alive = true;
}
context.validate_headers();
if (config_.logger)
config_.logger->http_server_request(req);
try
{
switch (req.get_method())
{
case http_method::head:
case http_method::get:
derived().on_get(context, head);
break;
case http_method::post:
derived().on_post(context);
break;
default:
BOOST_THROW_EXCEPTION(http_exception(http_status_code::method_not_allowed));
}
}
catch(http_exception&)
{
throw;
}
catch (interrupted_exception&)
{
throw;
}
catch (std::exception&)
{
BOOST_THROW_EXCEPTION(http_exception(http_status_code::internal_service_error));
}
}
catch (http_exception& e)
{
if (config_.logger)
config_.logger->exception();
res.set_status_code(e.status_code());
try
{
auto it = config_.error_document.find(e.status_code());
if (it != config_.error_document.end())
BOOST_THROW_EXCEPTION(http_exception(http_status_code::not_found));
req.set_path(it->second);
derived().on_get(context, head);
}
catch (http_exception&)
{
null_content().on_get(context, head);
}
}
context.finish_write();
//.........这里部分代码省略.........