本文整理汇总了C++中ostream::bad方法的典型用法代码示例。如果您正苦于以下问题:C++ ostream::bad方法的具体用法?C++ ostream::bad怎么用?C++ ostream::bad使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ostream
的用法示例。
在下文中一共展示了ostream::bad方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: write_genotypes
int hivpopulation::write_genotypes(ostream &out, int sample_size, string gt_label, int start, int length){
if (HIVPOP_VERBOSE) cerr<<"hivpopulation::write_genotypes()...";
if (HIVPOP_VERBOSE) cerr<<"start = "<<start<<"...";
if (HIVPOP_VERBOSE) cerr<<"length = "<<length<<"...";
if (out.bad()){
cerr<<"hivpopulation::write_genotypes(): BAD OUTPUT FILE!"<<endl;
return HIVPOP_BADARG;
}else{
int gti;
string temp;
if (length <= 0)
length = number_of_loci - start;
produce_random_sample(sample_size);
if (sample_size>get_population_size()){
cerr<<"hivpopulation::write_genotypes(): requested sample size exceeds population size"<<endl;
return HIVPOP_BADARG;
}else{
for (int s=0; s<sample_size; s++){
gti=random_clone();
out <<">GT-"<<gt_label<<"_"<<gti<<'\n';
for (int i =start; i<start+length; i++ ){
if (population[gti].genotype[i]) out <<'1';
else out <<'0';
}
out<<'\n';
}
}
if (HIVPOP_VERBOSE) cerr<<"...done."<<endl;
return 0;
}
}
示例2: write_coeff
//write coeff to a stream. This will write pairs of bistrings and values to the stream
int hypercube_lowd::write_coeff(ostream &out, bool label)
{
int i,k;
if (out.bad())
{
cerr <<"hypercube_lowd::write_coeff: bad stream\n";
return HC_BADARG;
}
i=0;
while(out.good() && i<(1<<dim))
{
if (label)
{
for (k=0; k<dim; k++)
{
if (i&(1<<k)) out <<'1';
else out <<'0';
}
out <<" ";
}
out <<coeff[i]<<endl;
i++;
}
if (i<(1<<dim))
{
cerr <<"hypercube_lowd::write_coeff: error while writing!\n";
return HC_BADARG;
}
return 0;
}
示例3: writeTo
//--------------------------------------------------
bool ofBuffer::writeTo(ostream & stream) const {
if(stream.bad()){
return false;
}
stream.write(&(buffer[0]), buffer.size() - 1);
return true;
}
示例4: DumpSymbols
//=============================================================================
// Function: DumpSymbols
//
// Parameters:
// LPTSTR lpszLibPathName - The library file path name
// CStdioFile* pFile - Address of the file in which to dump the symbols
//
// Description:
//
// Given a library file path name, the function dumps the symbol info into the file
// pointed to by pFile.
//=============================================================================
BOOL CLibSymbolInfo::DumpSymbols(LPTSTR lpszLibPathName, ostream& pFile)
{
if(lpszLibPathName == NULL || pFile.bad() ) {
assert(lpszLibPathName != NULL);
assert(pFile.good());
m_strErrorMsg.assign("NULL <lpszLibPathName> or Invalid file handle.");
return FALSE;
}
if(!Dump(lpszLibPathName, pFile)) return FALSE;
return TRUE;
}
示例5: write_func
//write func to a stream
int hypercube_lowd::write_func(ostream &out)
{
int i;
if (out.bad())
{
cerr <<"hypercube_lowd::write_func: bad stream\n";
return HC_BADARG;
}
i=0;
while(out.good() && i<(1<<dim))
{
out <<func[i]<<endl;
i++;
}
if (i<(1<<dim))
{
cerr <<"hypercube_lowd::write_func: error while writing!\n";
return HC_BADARG;
}
return 0;
}
示例6: Unpack
uint64_t PackUtils::Unpack(istream& in, uint64_t size, ostream& out)
{
uint64_t result = 0;
int ret;
uint64_t remaining = size;
uint64_t have;
z_stream strm;
char readBuf[PackUtils::CHUNK];
char writeBuf[PackUtils::CHUNK];
/* allocate inflate state */
strm.zalloc = Z_NULL;
strm.zfree = Z_NULL;
strm.opaque = Z_NULL;
strm.avail_in = 0;
strm.next_in = Z_NULL;
ret = inflateInit(&strm);
if (ret != Z_OK)
return 0;
/* decompress until deflate stream ends or end of file */
do
{
strm.avail_in = PackUtils::CHUNK;
if(remaining < PackUtils::CHUNK)
{
strm.avail_in = (uInt)remaining;
}
remaining -= strm.avail_in;
if(!in.read(readBuf, strm.avail_in))
{
strm.avail_in = (uInt)in.gcount();
}
if (in.bad())
{
(void)inflateEnd(&strm);
return 0;
}
if (strm.avail_in == 0)
break;
strm.next_in = (Bytef*) readBuf;
/* run inflate() on input until output buffer not full */
do
{
strm.avail_out = CHUNK;
strm.next_out = (Bytef*) writeBuf;
ret = inflate(&strm, Z_NO_FLUSH);
switch (ret)
{
case Z_NEED_DICT:
ret = Z_DATA_ERROR; /* and fall through */
case Z_DATA_ERROR:
case Z_MEM_ERROR:
(void)inflateEnd(&strm);
return 0;
}
have = CHUNK - strm.avail_out;
result += have;
out.write(writeBuf, have);
if (out.bad())
{
(void)inflateEnd(&strm);
return 0;
}
} while (strm.avail_out == 0);
/* done when inflate() says it's done */
} while (ret != Z_STREAM_END);
/* clean up and return */
(void)inflateEnd(&strm);
return ret == Z_STREAM_END ? result : 0;
}
示例7: Pack
uint64_t PackUtils::Pack(istream& in, ostream& out)
{
uint64_t result = 0;
char readBuf[PackUtils::CHUNK];
char writeBuf[PackUtils::CHUNK];
int ret, flush;
uint64_t have;
z_stream strm;
/* allocate deflate state */
strm.zalloc = Z_NULL;
strm.zfree = Z_NULL;
strm.opaque = Z_NULL;
ret = deflateInit(&strm, Z_DEFAULT_COMPRESSION);
// Couldn't init deflate
if (ret != Z_OK)
{
return 0;
}
do
{
strm.avail_in = PackUtils::CHUNK;
if(!in.read(readBuf, PackUtils::CHUNK))
{
strm.avail_in = (uInt)in.gcount();
}
if(in.bad())
{
(void)deflateEnd(&strm);
return 0;
}
flush = (in.eof() || strm.avail_in == 0) ? Z_FINISH : Z_NO_FLUSH;
strm.next_in = (Bytef*) readBuf;
/* run deflate() on input until output buffer not full, finish
compression if all of source has been read in */
do
{
strm.avail_out = CHUNK;
strm.next_out = (Bytef*) writeBuf;
ret = deflate(&strm, flush); /* no bad return value */
have = CHUNK - strm.avail_out;
result += have;
out.write(writeBuf, have);
if (out.bad())
{
(void) deflateEnd(&strm);
return 0;
}
} while (strm.avail_out == 0);
/* done when last data in file processed */
} while (flush != Z_FINISH);
/* clean up and return */
(void)deflateEnd(&strm);
in.clear();
return result;
}