本文整理汇总了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;
}
示例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;
}
示例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);
}
示例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;
}
}
示例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;
}
}