當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。