本文整理汇总了C++中std::fstream类的典型用法代码示例。如果您正苦于以下问题:C++ fstream类的具体用法?C++ fstream怎么用?C++ fstream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了fstream类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: saveContextSettingsToFile
bool Context::saveContextSettingsToFile( std::fstream &file ) const{
if( !file.is_open() ){
errorLog << "saveContextSettingsToFile(fstream &file) - The file is not open!" << std::endl;
return false;
}
if( !MLBase::saveBaseSettingsToFile( file ) ) return false;
file << "Initialized: " << initialized << std::endl;
return true;
}
开发者ID:CV-IP,项目名称:grt,代码行数:13,代码来源:Context.cpp
示例2: new
MemoryAccessor::MemoryAccessor( GsTLInt size, std::fstream& stream ) {
values_ = new(std::nothrow) float[size];
flags_ = new(std::nothrow) bool[size];
if(values_ == NULL || flags_ == NULL) size_ = 0;
else {
size_ = size;
if( !stream.is_open() ) {
GsTLlog << "Error: Stream not open when trying to swap property to memory!!"
<< gstlIO::end;
}
stream.seekg(0);
long int remaining = size*sizeof( float );
stream.read( (char*) values_, remaining );
// read the flags
remaining = size*sizeof( bool );
stream.read( (char*) flags_, remaining );
}
}
开发者ID:TUDz,项目名称:ar2tech-SGeMS-public,代码行数:22,代码来源:grid_property.cpp
示例3: unpatch
bool unpatch(std::fstream &file, char* buffer, size_t size)
{
std::vector<size_t> regemu;
find_all(buffer, "REGEMU32", size, 8, regemu);
if (!regemu.empty())
{
for (size_t pos : regemu)
{
file.seekg(pos, std::ios::beg);
file.write("ADVAPI32", 8);
}
wprintf(L"REGEMU32 found (%d) and unpatched. ", regemu.size());
}
else
{
wprintf(L"REGEMU32 not found. ");
}
return !regemu.empty();
}
开发者ID:KrossX,项目名称:RegEmu32,代码行数:22,代码来源:Patcher.cpp
示例4: search_forward
std::streampos search_forward ( std::fstream & _bs, const std::string & sample )
{
size_t match ( 0 );
cSaveIStreamPosition ip ( &_bs );
streampos result ( static_cast<streampos>( -1 ) );
cSaveStreamExceptions se ( &_bs, std::ios_base::goodbit );
for( int ch( EOF ); match < sample.length(); match++ )
{
ch = _bs.get();
if( ch == EOF )
break;
else if( ch != sample[match] )
match = 0;
}
if( match == sample.length() )
result = _bs.tellg() - static_cast<streampos>( match );
_bs.clear();
return result;
}
开发者ID:o-peregudov,项目名称:libcrs,代码行数:22,代码来源:parsing.cpp
示例5: save
bool ClassLabelChangeFilter::save( std::fstream &file ) const {
if( !file.is_open() ){
errorLog << "save(fstream &file) - The file is not open!" << std::endl;
return false;
}
file << "GRT_CLASS_LABEL_CHANGE_FILTER_FILE_V1.0" << std::endl;
file << "NumInputDimensions: " << numInputDimensions << std::endl;
file << "NumOutputDimensions: " << numOutputDimensions << std::endl;
return true;
}
开发者ID:nickgillian,项目名称:grt,代码行数:13,代码来源:ClassLabelChangeFilter.cpp
示例6: write_var
void write_var(std::fstream &stream, T variable)
{
static_assert(std::is_signed<T>::value == false, "Value must be unsigned");
constexpr const BYTE ZERO_BITTED = std::numeric_limits<BYTE>::max() / 2;
constexpr const BYTE ONE_BITTED = ZERO_BITTED + 1;
loop:
{
if ((variable & ~ZERO_BITTED) == 0)
{
stream.put(static_cast<BYTE>(variable));
return;
}
else
{
stream.put(static_cast<BYTE>((variable & ZERO_BITTED) | ONE_BITTED));
variable >>= 7;
}
}
goto loop;
}
开发者ID:BourgondAries,项目名称:Cxy-v0.1.0-draft.1,代码行数:22,代码来源:write_var.hpp
示例7: ReadElectricField
inline void ReadElectricField(std::fstream& field_file) {
std::string line;
assert(field_file.is_open());
getline(field_file, line);
const std::vector<std::string> split_line = Split(line, ' ');
std::vector<std::string>::const_iterator i_split = split_line.begin();
for (int i_atom = 0; i_atom < group_size_; i_atom++) {
for (int i_dim = 0; i_dim < DIMS; i_dim++) {
electric_fields_(i_atom,i_dim) = atof((*i_split).c_str());
i_split++;
}
}
}
开发者ID:thekannman,项目名称:z_rdf,代码行数:13,代码来源:z_particle_group.hpp
示例8: load
bool RBMQuantizer::load( std::fstream &file ){
//Clear any previous model
clear();
if( !file.is_open() ){
errorLog << "load(fstream &file) - The file is not open!" << std::endl;
return false;
}
std::string word;
//First, you should read and validate the header
file >> word;
if( word != "RBM_QUANTIZER_FILE_V1.0" ){
errorLog << "load(fstream &file) - Invalid file format!" << std::endl;
return false;
}
//Second, you should load the base feature extraction settings to the file
if( !loadFeatureExtractionSettingsFromFile( file ) ){
errorLog << "loadFeatureExtractionSettingsFromFile(fstream &file) - Failed to load base feature extraction settings from file!" << std::endl;
return false;
}
file >> word;
if( word != "QuantizerTrained:" ){
errorLog << "load(fstream &file) - Failed to load QuantizerTrained!" << std::endl;
return false;
}
file >> trained;
file >> word;
if( word != "NumClusters:" ){
errorLog << "load(fstream &file) - Failed to load NumClusters!" << std::endl;
return false;
}
file >> numClusters;
if( trained ){
if( !rbm.load( file ) ){
errorLog << "load(fstream &file) - Failed to load SelfOrganizingMap settings from file!" << std::endl;
return false;
}
initialized = true;
featureDataReady = false;
quantizationDistances.resize(numClusters,0);
}
return true;
}
开发者ID:sgrignard,项目名称:grt,代码行数:51,代码来源:RBMQuantizer.cpp
示例9: WriteHeader
void PEObject::WriteHeader(std::fstream &stream)
{
unsigned zero = 0;
for (int i =0; i < name.size() && i < 8; i++)
stream.write(&name[i], 1);
for (int i = name.size(); i < 8; i++)
stream.write((char *)&zero, 1);
unsigned msize = ObjectAlign(objectAlign, size);
stream.write((char *)&msize, 4);
stream.write((char *)&virtual_addr, 4);
msize = ObjectAlign(fileAlign, initSize);
stream.write((char *)&msize, 4);
stream.write((char *)&raw_addr, 4);
stream.write((char *)&zero, 4);
stream.write((char *)&zero, 4);
stream.write((char *)&zero, 4);
int flg = (flags ^ WINF_NEG_FLAGS) & WINF_IMAGE_FLAGS; /* get characteristice for section */
stream.write((char *)&flg, 4);
}
开发者ID:doniexun,项目名称:OrangeC,代码行数:19,代码来源:PEObject.cpp
示例10: printFile
void printFile(std::fstream &file, const char filename[]) {
file.seekg(0, file.end);
int fileSize = file.tellg();
contact contacts[ROWS_TOTAL_COUNT];
std::ifstream fileToRead;
fileToRead.open(filename, std::ios::binary | std::ios::in);
if (fileToRead.fail()) {
std::cout << "Не удается открыть файл\n";
exit(1);
}
fileToRead.seekg(0, fileToRead.beg);
bool formatError = false;
std::cout << std::endl << "***************** Prinitng file ****************" << std::endl << std::endl;
for (int i = 0; i < fileSize / ROW_LENGTH; i++) {
fileToRead.read(contacts[i].firstName, NAME_LENGTH);
fileToRead.read(contacts[i].lastName, NAME_LENGTH);
fileToRead.read(contacts[i].phone, PHONE_LENGTH);
std::cout << std::setw(NAME_LENGTH) << contacts[i].firstName << " | ";
std::cout << std::setw(NAME_LENGTH) << contacts[i].lastName << " | ";
std::cout << contacts[i].phone << std::endl;
if (contacts[i].phone[1] != '(' || contacts[i].phone[5] != ')' || contacts[i].phone[9] != '-') {
formatError = true;
}
}
std::cout << std::endl << "***************** end of file ******************" << std::endl << std::endl;
std::cout << "Length of the file should be " << ROW_LENGTH * ROWS_TOTAL_COUNT << ", got " << fileSize << std::endl;
if (!formatError) {
std::cout << "Correct formatting" << std::endl;
}
else {
std::cout << "Error: incorrect formatting" << std::endl;
}
fileToRead.close();
}
开发者ID:zwug,项目名称:homework,代码行数:38,代码来源:main.cpp
示例11: SaveLuaTable
void LuaHistoryFile::SaveLuaTable(lua_State* luaState, int nIndex, size_t nBufferLen, std::fstream& fileStream)
{
vector<string> vecStrings;
if(lua_istable(luaState,nIndex))
{
int nStrCnt = lua_objlen(luaState,nIndex);
const char* cszWrite = NULL;
for(int ix = 1; ix <= nStrCnt; ++ix)
{
lua_rawgeti(luaState, nIndex , ix);
if(lua_isstring(luaState, -1))
{
cszWrite = luaL_checkstring(luaState, -1);
wstring wstrWrite;
UTF8_to_Unicode(cszWrite, strlen(cszWrite), wstrWrite);
string astrWrite;
wstrWrite += WCHAR('\n');
Unicode_to_ANSI(wstrWrite.c_str(), wstrWrite.size(),astrWrite);
vecStrings.push_back(astrWrite);
}
lua_pop(luaState,1);
}
}
char szStrCnt[100];
itoa(vecStrings.size(), szStrCnt, 100);
int nStrCntLen = strlen(szStrCnt);
szStrCnt[nStrCntLen] = '\n';
fileStream.write(szStrCnt, nStrCntLen + 1);
for(size_t ix = 0; ix < vecStrings.size(); ++ix)
{
const char* buf = vecStrings[ix].c_str();
size_t buflen = vecStrings[ix].size();
fileStream.write(buf, buflen);
}
}
开发者ID:fanliaokeji,项目名称:lvdun,代码行数:38,代码来源:HistroyFile.cpp
示例12: loadModelFromFile
bool ClassLabelFilter::loadModelFromFile( std::fstream &file ){
if( !file.is_open() ){
errorLog << "loadModelFromFile(fstream &file) - The file is not open!" << std::endl;
return false;
}
std::string word;
//Load the header
file >> word;
if( word != "GRT_CLASS_LABEL_FILTER_FILE_V1.0" ){
errorLog << "loadModelFromFile(fstream &file) - Invalid file format!" << std::endl;
return false;
}
file >> word;
if( word != "NumInputDimensions:" ){
errorLog << "loadModelFromFile(fstream &file) - Failed to read NumInputDimensions header!" << std::endl;
return false;
}
file >> numInputDimensions;
//Load the number of output dimensions
file >> word;
if( word != "NumOutputDimensions:" ){
errorLog << "loadModelFromFile(fstream &file) - Failed to read NumOutputDimensions header!" << std::endl;
return false;
}
file >> numOutputDimensions;
//Load the minimumCount
file >> word;
if( word != "MinimumCount:" ){
errorLog << "loadModelFromFile(fstream &file) - Failed to read MinimumCount header!" << std::endl;
return false;
}
file >> minimumCount;
file >> word;
if( word != "BufferSize:" ){
errorLog << "loadModelFromFile(fstream &file) - Failed to read BufferSize header!" << std::endl;
return false;
}
file >> bufferSize;
//Init the classLabelFilter module to ensure everything is initialized correctly
return init(minimumCount,bufferSize);
}
开发者ID:BryanBo-Cao,项目名称:grt,代码行数:50,代码来源:ClassLabelFilter.cpp
示例13: setProgName
// sets the prog name. Requires a file pointer. Extracts exactly six characters
// from fstream
void HeaderRecord::setProgName(std::fstream & file) {
int i;
// get 6 characters and append them to the progName string
for (i = 0; i < 6; i++) {
// needs a string argument for append()
char tempChar = file.get();
// error handler, check for eof bit
Record::unexpectedEOF(file);
// append to string
progName += tempChar;
}
std::cout << "Program name: " + progName;
}
开发者ID:brandonrogers,项目名称:Sic-XE-Disassembler,代码行数:16,代码来源:HeaderRecord.cpp
示例14: ReadFrom
/// Reads from file stream.
void Tile::ReadFrom(std::fstream & file){
// Read version
int version;
file.read((char*)&version, sizeof(int));
assert(tileVersion == version);
// Read type
file.read((char*)&typeIndex, sizeof(int));
// Read position.
position.ReadFrom(file);
// Write stuff bound to the tile.
int stuff = 0;
file.read((char*)&stuff, sizeof(int));
// If got event
if (stuff & 0x001){
// Load event source
event = new Script();
event->source.ReadFrom(file);
// Load it straight away, or...?
}
// Write description of additional details to file.
description.WriteTo(file);
}
开发者ID:erenik,项目名称:engine,代码行数:24,代码来源:Tile.cpp
示例15: loadModelFromFile
bool ClassLabelTimeoutFilter::loadModelFromFile( std::fstream &file ){
if( !file.is_open() ){
errorLog << "loadModelFromFile(fstream &file) - The file is not open!" << std::endl;
return false;
}
std::string word;
//Load the header
file >> word;
if( word != "GRT_CLASS_LABEL_TIMEOUT_FILTER_FILE_V1.0" ){
errorLog << "loadModelFromFile(fstream &file) - Invalid file format!" << std::endl;
return false;
}
file >> word;
if( word != "NumInputDimensions:" ){
errorLog << "loadModelFromFile(fstream &file) - Failed to read NumInputDimensions header!" << std::endl;
return false;
}
file >> numInputDimensions;
//Load the number of output dimensions
file >> word;
if( word != "NumOutputDimensions:" ){
errorLog << "loadModelFromFile(fstream &file) - Failed to read NumOutputDimensions header!" << std::endl;
return false;
}
file >> numOutputDimensions;
//Load the filterMode
file >> word;
if( word != "FilterMode:" ){
errorLog << "loadModelFromFile(fstream &file) - Failed to read FilterMode header!" << std::endl;
return false;
}
file >> filterMode;
file >> word;
if( word != "TimeoutDuration:" ){
errorLog << "loadModelFromFile(fstream &file) - Failed to read TimeoutDuration header!" << std::endl;
return false;
}
file >> timeoutDuration;
//Init the classLabelTimeoutFilter module to ensure everything is initialized correctly
return init(timeoutDuration,filterMode);
}
开发者ID:BryanBo-Cao,项目名称:grt,代码行数:50,代码来源:ClassLabelTimeoutFilter.cpp
示例16: LoadLuaTable
int LuaHistoryFile::LoadLuaTable(lua_State* luaState, size_t nBufferLen, std::fstream& fileStream)
{
char* szRead = new char[4 * nBufferLen];
lua_newtable(luaState);
if(fileStream.getline(szRead, 4 * nBufferLen))
{
int nStrCnt = atoi(szRead);
for(int ix = 1; ix <= nStrCnt; ++ix)
{
if(fileStream.getline(szRead, 4 * nBufferLen))
{
string strRead;
wstring wstrRead;
ANSI_to_Unicode(szRead, strlen(szRead), wstrRead);
Unicode_to_UTF8(wstrRead.c_str(), wstrRead.size(), strRead);
lua_pushstring(luaState, strRead.c_str());
lua_rawseti(luaState, -2, ix);
}
}
}
delete []szRead;
return 1;
}
开发者ID:fanliaokeji,项目名称:lvdun,代码行数:23,代码来源:HistroyFile.cpp
示例17: WriteTo
/// Writes to file stream.
void Tile::WriteTo(std::fstream & file)
{
// Write version
file.write((char*)&tileVersion, sizeof(int));
// Fetch type index.
this->typeIndex = -1;
if (type)
typeIndex = type->type;
// Write type index
file.write((char*)&typeIndex, sizeof(int));
// Write position.
position.WriteTo(file);
// Write stuff bound to the tile.
int stuff = 0;
if (event)
stuff |= 0x001;
file.write((char*)&stuff, sizeof(int));
// Write the path to the source of the event.
if (event)
event->source.WriteTo(file);
// Write description of additional details to file.
description.WriteTo(file);
}
开发者ID:erenik,项目名称:engine,代码行数:24,代码来源:Tile.cpp
示例18: readBoolean
static void readBoolean(std::fstream &str, bool &res)
{
if(!str.good()){
return;
}
std::string tmp;
str>>tmp;
std::transform(tmp.begin(), tmp.end(), tmp.begin(), ::tolower);
if(tmp.find("true", 0) != std::string::npos){
res = true;
}else{
res = false;
}
}
开发者ID:sparker256,项目名称:xchecklist,代码行数:14,代码来源:Xchecklist.cpp
示例19: getmem
void
getmem(const std::string& pid,std::fstream& tsdbfile,std::string metric)//Get memory information (in one block right now)
{
metric+=".mem";
std::string path="/proc/"+pid+"/statm";
std::ifstream file(path,std::ifstream::binary);
std::string content((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
size_t pos = 0;
std::string token;
std::string delim=" ";
std::string metrics[]={"VmSize","VMRSS","shr-pgs","code","NA","Data_and_stack"};
int met_pos=0;
tsdbfile.open ("tcollector_proc.out",std::fstream::app);
while ((pos = content.find(delim)) != std::string::npos) {
token = content.substr(0, pos);
content.erase(0, pos + delim.length());
tsdb_stdout(tsdbfile,metric+"."+metrics[met_pos],token);
met_pos+=1;
}
tsdbfile.close();
return ;
}
开发者ID:apmechev,项目名称:procfsamp,代码行数:23,代码来源:procfscollector.cpp
示例20: LCSOpenFileCPP
//C++ file i/o version of the above.
bool LCSOpenFileCPP(std::string filename, std::ios_base::openmode mode, int flags, std::fstream &file)
{
if(!initialized) //Check if the directories have not been initialized.
{
LCSInitHomeDir(); //Initialize the home directory of LCS. Where stuff like the save and score files are stored.
LCSInitArtDir(); //Initialize the art dir.
initialized = true; //Initialized.
}
std::string filepath = ""; //The actual path to the file.
//This ifelse block decides which directory the file gets saved to.
if(flags & LCSIO_PRE_ART) //Art dir specified.
filepath = artdir; //Set the filepath to the artdir.
else if(flags & LCSIO_PRE_HOME) //Home dir specified.
filepath = homedir; //Set the filepath to the homedir.
filepath.append(filename); //Append the file's name/relative path to the filepath.
file.open(filepath.c_str(), mode); //Opens the file.
return file.is_open(); //Check if file opened successfully.
}
开发者ID:DanielOaks,项目名称:Liberal-Crime-Squad,代码行数:24,代码来源:lcsio.cpp
注:本文中的std::fstream类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论