本文整理汇总了C++中std::fstream::good方法的典型用法代码示例。如果您正苦于以下问题:C++ fstream::good方法的具体用法?C++ fstream::good怎么用?C++ fstream::good使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::fstream
的用法示例。
在下文中一共展示了fstream::good方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: checkIfWriteSucceed
void checkIfWriteSucceed(std::fstream& logFile)
{
// The logFile.good returns 1 if everything was ok at the last op.
// exitIfFail checks if the number she gets is not zero, so we use the not
// to flip good to match exitIfFail
exitIfFail(!logFile.good());
}
示例2: OpenFile
bool OpenFile(const std::wstring& aFile, std::fstream& aStream,
std::ios_base::open_mode aMode)
{
std::string s;
aStream.open(Ucs2ToUtf8(aFile, s).c_str(), aMode);
return aStream.good();
}
示例3:
static bool loadY4MHeader(std::fstream& fs, cv::Mat &img)
{
fs.seekg(fs.beg);
if (fs.good())
{
char inbuf [256];
fs >> inbuf;
if (strcmp(inbuf, "YUV4MPEG2") != 0)
{
return false;
}
fs.get(); // space
int width, height;
char c = fs.get();
if (c != 'W')
{
return false;
}
fs >> width;
c = fs.get();// space
c = fs.get();
if (c != 'H')
{
return false;
}
fs >> height;
img.create(height * 3 / 2, width, CV_8UC1);
}
示例4: Save
bool Organism::Save (std::fstream &File) const {
// File format:
// StateCount sizeof (int)
// SensorCount sizeof (int)
// CurrentState sizeof (int)
// States sizeof (State) * StateCount
// Sensors sizeof (Sensor) * SensorCount
// OrgGenome varies
File.write ((const char *) &StateCount, sizeof (int));
File.write ((const char *) &SensorCount, sizeof (int));
File.write ((const char *) &CurrentState, sizeof (int));
// Save states:
int i;
for (i = 0; i < StateCount; i++) {
if (!States [i].Save (File))
return false;
}
// Save sensors:
for (i = 0; i < SensorCount; i++) {
if (!Sensors [i].Save (File))
return false;
}
// Save the genome:
if (!OrgGenome.Save (File))
return false;
if (!File.good ())
return false;
return true;
}
示例5: Load
bool Organism::Load (std::fstream &File) {
File.read ((char *) &StateCount, sizeof (int));
File.read ((char *) &SensorCount, sizeof (int));
File.read ((char *) &CurrentState, sizeof (int));
// Allocate memory for states:
delete [] States;
States = new State [StateCount];
// Load states:
int i;
for (i = 0; i < StateCount; i++) {
if (!States [i].Load (File))
return false;
}
// Allocate memory for the sensors:
delete [] Sensors;
Sensors = new Sensor [SensorCount];
// Load sensors:
for (i = 0; i < SensorCount; i++) {
if (!Sensors [i].Load (File))
return false;
}
// Load the genome:
if (!OrgGenome.Load (File))
return false;
if (!File.good ())
return false;
return true;
}
示例6: encryptData
bool XorEncryptor::encryptData(std::fstream &original, std::fstream &result)
{
if (!original.is_open() || !result.is_open())
{
return false;
}
original.seekg(0, std::ios::beg);
result.seekp(0, std::ios::beg);
char c = 0;
unsigned i = 0;
while (original.good())
{
original.read(&c, 1);
c ^= password[i];
if(original.gcount() > 0)
{
result.write(&c, 1);
}
if (++i == passSize)
{
i = 0;
}
}
original.seekg(0, std::ios::beg);
result.seekg(0, std::ios::beg);
result.flush();
return true;
}
示例7: write
bool write(std::fstream& file, Json::Value const& root)
{
Json::StyledWriter writer;
std::string val = writer.write(root);
LOG4CPLUS_INFO(CFileStorage::msLogger, val);
file << val;
file.flush();
file.seekg(0, ios::beg);
return file.good();
}
示例8: manageFile
void manageFile(std::fstream &InputFile, std::vector<Operator> &operators)
{
std::cout << "File is opened" << std::endl;
if (InputFile.good())
{
std::string line = "";
while (std::getline(InputFile, line))
{
fillOperators(line, operators);
}
}
}
示例9: 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;
}
}
示例10:
bool CLayer:: read_layer_multi_contour_with_z(std::fstream& fin)
{
int pos=-1;
float levelID;
int contourID;
bool result=true;
if (fin.good())
{
pos=fin.tellg();
fin>>levelID;
fin>>contourID;
fin.seekg(pos);
}
示例11: sizeof
bool Organism::State::Save (std::fstream &File) {
// File format:
// Count sizeof (int)
// Name sizeof (char) * Count
int Count = Name.size() + 1;
File.write ((const char *) &Count, sizeof (int));
File.write ((const char *) Name.c_str(), sizeof (char) * Count);
if (!File.good ())
return false;
return true;
}
示例12: checkformodifications
void resultsfile::checkformodifications(std::fstream& file)
{
assert(file.good());
trace << "DEBUG (resultsfile): checking file for modifications." << std::endl;
// check for user modifications
sha curdigest;
file.seekg(0);
curdigest.process(file);
// reset file
file.clear();
if (curdigest == filedigest)
file.seekp(fileptr);
else
{
cerr << "NOTICE: file modifications found - appending." << std::endl;
// set current write position to end-of-file
file.seekp(0, std::ios_base::end);
fileptr = file.tellp();
}
}
示例13: ReadLine
////////////////////////////////////////////////////////////////////////////////////
///
/// \brief Reads a line from a fstream adding it to a string, reading up
/// to a newline character.
///
/// \param[in] str File stream operator.
/// \param[out] line Line read from file (doesn't include carriage return).
///
/// \return Number of characters read.
///
////////////////////////////////////////////////////////////////////////////////////
unsigned int FileIO::ReadLine(std::fstream& str,
std::string& line)
{
char ch;
line.reserve(512);
line.clear();
while(str.eof() == false && str.good())
{
str.get(ch);
if(ch == '\n')
{
break;
}
else
{
line.push_back(ch);
}
}
return (unsigned int)line.size();
}
示例14: main
int main()
{
f1.open("/Users/robinmalhotra2/Desktop/csl201check.txt",std::ios::in|std::ios::out);
f1.getline(s, 80, ' ');
while (f1.good())
{
std::cout<<"addasd";
if ((strlen(s)==1) && (s[0])<'9' && (s[0])>'0')
{
switch ((s[0]))
{
case '1':
createandprintlist();
break;
case '2':
sortlist();
break;
case '3':
nextinsert();
break;
case '4':
searchlist();
break;
case '5':
deletenext();
break;
case '6':
deduplicate();
break;
case '7':
mergesortthing();
break;
case '8':
credits();
break;
default:
break;
}
}
}
f1.close();
}
示例15: IsValid
bool OsFileImpl::IsValid() const
{
return mFile.good();
}