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


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

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


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

示例1: test_seekable_in_chars

bool test_seekable_in_chars(std::iostream& io)
{
    int i;  // old 'for' scope workaround.

    // Test seeking with ios::cur
    for (i = 0; i < data_reps; ++i) {
        int j;
        for (j = 0; j < chunk_size; ++j)
            io.put(narrow_data()[j]);
        io.seekp(-chunk_size, BOOST_IOS::cur);
        for (j = 0; j < chunk_size; ++j)
            if (io.get() != narrow_data()[j])
               return false;
        io.seekp(-chunk_size, BOOST_IOS::cur);
        for (j = 0; j < chunk_size; ++j)
            io.put(narrow_data()[j]);
    }

    // Test seeking with ios::beg
    std::streamoff off = 0;
    io.seekp(0, BOOST_IOS::beg);
    for (i = 0; i < data_reps; ++i, off += chunk_size) {
        int j;
        for (j = 0; j < chunk_size; ++j)
            io.put(narrow_data()[j]);
        io.seekp(off, BOOST_IOS::beg);
        for (j = 0; j < chunk_size; ++j)
            if (io.get() != narrow_data()[j])
               return false;
        io.seekp(off, BOOST_IOS::beg);
        for (j = 0; j < chunk_size; ++j)
            io.put(narrow_data()[j]);
    }

    // Test seeking with ios::end
    io.seekp(0, BOOST_IOS::end);
    off = io.tellp();
    io.seekp(-off, BOOST_IOS::end);
    for (i = 0; i < data_reps; ++i, off -= chunk_size) {
        int j;
        for (j = 0; j < chunk_size; ++j)
            io.put(narrow_data()[j]);
        io.seekp(-off, BOOST_IOS::end);
        for (j = 0; j < chunk_size; ++j)
            if (io.get() != narrow_data()[j])
               return false;
        io.seekp(-off, BOOST_IOS::end);
        for (j = 0; j < chunk_size; ++j)
            io.put(narrow_data()[j]);
    }
    return true;
}
开发者ID:AsherBond,项目名称:PDAL,代码行数:52,代码来源:verification.hpp

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