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


C++ std::ifstream方法代码示例

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


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

示例1: main

int main(int argc, char **argv)
{
    setlocale(0, "Russian");
    ifstream In = ifstream("input.txt");

    if(!In.is_open())
    {
        printf_s("Нет файла :(\n");
        return -1;
    }

    Sphere s1 = ReadSphere(In);
    Sphere s2 = ReadSphere(In);

    In.close();

    PrintSphere(s1,1);
    PrintSphere(s2,2);

    ofstream Out = ofstream("output.txt");
    if(IsSphereContect(s1,s2))
    {
        Out<<"YES";
        printf("Сферы пересикаются\n");
    } else {
        Out<<"NO";
        printf("Сферы не пересикаются\n");
    }

    Out.close();
    return EXIT_SUCCESS;
}
开发者ID:apcel,项目名称:ivb-3-14,代码行数:32,代码来源:lab4.cpp

示例2: ifstream

Counter::Counter(string fileName, size_t readerRank, size_t readerSize)
  : _fn{fileName}
  , _offset{0}
  , _length{0}
  , _fileSize{0}
{
  auto&& tmp = ifstream(_fn);
  tmp.seekg(0, ios_base::end);
  _fileSize = tmp.tellg();

  auto minReading = _fileSize / readerSize;
  
  auto rest = _fileSize - minReading * readerSize;

  auto offsets = vector<size_t>{};
  auto lengths = vector<size_t>{};
  auto curOffset = 0u;

  for(auto i = 0u; i < readerSize; ++i)
    {
      offsets.push_back(curOffset);
      lengths.push_back( minReading + (i  <  rest ? 1 : 0  ) );
      curOffset += lengths.back();
    }

  _offset = offsets.at(readerRank);
  _length = lengths.at(readerRank);
  
  std::fill(_counts, _counts + 256, 0u );
  
  // cout << "thread " << readerRank << " / " << readerSize << " reading at offset " << _offset << " for length " << _length << endl; 
}
开发者ID:aberer,项目名称:count-char,代码行数:32,代码来源:Counter.cpp

示例3: load

bool Image::load(RenderDevice* device, const String& imageFile)
{
	using std::ifstream;
	using std::ios;

	rc::ResourceLoader loader;

	tsinfo("Loading image: \"%\"", imageFile);

	loader.load(ifstream(imageFile, ios::binary));

	if (loader.fail())
	{
		tswarn("Unable to load image.");
		return !setError(true);
	}

	const auto& imgReader = loader.deserialize<tsr::Image>();

	const uint32 sign = imgReader.signature();
	tsassert(memcmp("TSTX", reinterpret_cast<const char*>(&sign), 4) == 0);

	ImageResourceInfo info;
	ResourceData data;

	data.memoryByteDepth = imgReader.byteDepth();
	data.memoryByteWidth = imgReader.byteWidth();
	data.memory = imgReader.data().data();

	info.format = (ImageFormat)imgReader.format();
	info.type = (ImageType)imgReader.type();
	info.usage = ImageUsage::SRV;
	info.height = imgReader.height();
	info.width = imgReader.width();
	info.length = imgReader.length();
	info.useMips = true;
	info.mipLevels = 1;
	info.msLevels = 1;

	//Create image resource
	m_img = device->createResourceImage(&data, info, m_img.release());

	if (!m_img)
	{
		tserror("Unable to create image.");
		return !setError(true);
	}

	//Save image info
	m_imgInfo = info;

	return !setError(false);
}
开发者ID:BrotherhoodOfHam,项目名称:Engine3D,代码行数:53,代码来源:Image.cpp

示例4: FileExists

bool FileExists(const char* Archivo){
	if(!ifstream(Archivo)){
		ofstream crear(Archivo);
		ofstream write;
		write.open(Archivo);
		write<<"Falso,0";
		write.close();
		crear.close();
		return true;
	}else{
		return true;
	}
		
}
开发者ID:intiv,项目名称:Proyecto1,代码行数:14,代码来源:main.cpp

示例5: count

void Counter::count()
{
  auto&& in = ifstream(_fn);
  in.seekg(_offset, ios_base::beg);
  
  auto numRead = 0u;
  while(numRead  < _length )
    {
      char c ;  
      in.get(c);
      ++_counts[static_cast<size_t>(c)];
      ++numRead; 
    }
}
开发者ID:aberer,项目名称:count-char,代码行数:14,代码来源:Counter.cpp


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