当前位置: 首页>>代码示例>>C++>>正文


C++ iostream::seekg方法代码示例

本文整理汇总了C++中std::iostream::seekg方法的典型用法代码示例。如果您正苦于以下问题:C++ iostream::seekg方法的具体用法?C++ iostream::seekg怎么用?C++ iostream::seekg使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在std::iostream的用法示例。


在下文中一共展示了iostream::seekg方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: inttostr

void	Client::setResponseContentLength(Transaction& trans, std::iostream& os)
{
  os.seekg(0, std::ios::end);
  int os_length = os.tellg();
  os_length--;
  os.seekg(0, std::ios::beg);
  trans.getResponse().getHeaders().setValue("CONTENT-LENGTH", inttostr(os_length));
}
开发者ID:Damax,项目名称:zia,代码行数:8,代码来源:Client.cpp

示例2: saveFile

bool ResourceManager::saveFile(const std::string& fileName, std::iostream& in)
{
    std::streampos oldPos = in.tellg();
    in.seekg(0, std::ios::end);
    std::streampos size = in.tellg();
    in.seekg(0, std::ios::beg);
    std::vector<char> buffer(size);
    in.read(&buffer[0], size);
    bool ret = saveFile(fileName, (const uchar*)&buffer[0], size);
    in.seekg(oldPos, std::ios::beg);
    return ret;
}
开发者ID:LeandroPerrotta,项目名称:otclient,代码行数:12,代码来源:resourcemanager.cpp

示例3: 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();
        }
    }
}
开发者ID:LeandroPerrotta,项目名称:otclient,代码行数:30,代码来源:resourcemanager.cpp

示例4: FillStream

void FillStream(std::iostream& strm, RawData& expression)
{
	static const std::string s_smallExpression("0123456789abcdefghijklmnopqrstuvwxyz");
	static const int iterationsCount = 10;

	for (int i = 0; i < iterationsCount; ++i)
	{
		strm << s_smallExpression;
	}
	size_t expressionSize = iterationsCount * s_smallExpression.size();
	expression.resize(expressionSize);
	strm.read(reinterpret_cast<char*>(&expression[0]), expressionSize);
	strm.seekg(0);
}
开发者ID:ElwooD07,项目名称:BdContainer,代码行数:14,代码来源:CryptingTest.cpp

示例5: GetAsString

std::string StringUtilities::GetAsString(std::iostream& i_stream)
{
	int length;
	char* p_buffer;
	
	// get length of file:
	i_stream.seekg (0, std::iostream::end);
	length = static_cast<int>(i_stream.tellg());
	i_stream.seekg (0, std::iostream::beg);

	// allocate memory:
	p_buffer = new char [length];
	//write file
	int pos = 0;
	while(i_stream.good())
	{
		p_buffer[pos] = i_stream.get();
		++pos;
	}

	std::string out(p_buffer, pos);
	delete[] p_buffer;
	return out;
}
开发者ID:TraurigeNarr,项目名称:SupportSDK,代码行数:24,代码来源:StringUtilities.cpp


注:本文中的std::iostream::seekg方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。