本文整理汇总了C++中std::istream::width方法的典型用法代码示例。如果您正苦于以下问题:C++ istream::width方法的具体用法?C++ istream::width怎么用?C++ istream::width使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::istream
的用法示例。
在下文中一共展示了istream::width方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loadHeader
int Narf::loadHeader(std::istream& file) const
{
size_t pos_in_file = file.tellg();
file.width(getHeaderKeyword().size()+10); // limit maximum number of bytes to read
std::string header;
file >> header;
file.width(0); // remove limit
if (header != getHeaderKeyword())
{
file.seekg(pos_in_file); // Go back to former pos in file
return -1;
}
int version;
file >> version;
file.ignore(1); // Skip the space after the version number
return version;
}
示例2: readString
// --------------------------------------------------------------------------
//
// --------------------------------------------------------------------------
int32_t VtkStructuredPointsReader::readString(std::istream& in, char* result, size_t length)
{
in.width(length);
in >> result;
if (in.fail())
{
return 0;
}
return 1;
}
示例3: readPTXM
unsigned int eft::readPTXM( std::istream &file )
{
unsigned int ptxmSize;
unsigned int total = readFormHeader( file, "PTXM", ptxmSize );
ptxmSize += 8;
std::cout << "Found FORM PTXM: " << ptxmSize-12 << " bytes"
<< std::endl;
unsigned int size;
std::string type;
total += readRecordHeader( file, type, size );
#if 0
if( type != "0002" )
{
std::cout << "Expected record of type 0002: " << type << std::endl;
throw std::exception();
}
#endif
std::cout << "Found record " << type
<< ": " << size << " bytes"
<< std::endl;
std::string name;
unsigned char num;
total += base::read( file, num );
#if 1
file.width( size - sizeof( unsigned char ) );
file >> name;
total += size;
#else
total += base::read( file, name );
#endif
std::cout << "Pixel shader texture " << (unsigned int)num
<< ": " << name << std::endl;
if( ptxmSize == total )
{
std::cout << "Finished reading PTXM" << std::endl;
}
else
{
std::cout << "FAILED in reading PTXM" << std::endl;
std::cout << "Read " << total << " out of " << ptxmSize
<< std::endl;
}
return total;
}
示例4: if
// Read name-value pairs from the stream. If the first item is a number, then
// we expect that many name-value pairs. If not, then we read until the end of
// the stream. Be sure not to duplicate the last one, and be sure to dump any
// items from a # to end-of-line.
// Parse for name-value pairs, where the pairs are separated by whitespace.
// *Every* parameter must be specified as a name-value pair (no single name
// with no value allowed). If we get a single name with no value that will
// screw up the name-value pairing for any remaining pairs. We could check for
// this situation, but for now we just let it happen and dump the errors. (i'll
// do a better parsing algorithm at some later point).
// We return the number of items that we were able to read from the stream.
// If we come across an item that is unrecognized, we dump an error message.
// The buffer length is limited here, so don't try to read in any really long
// lines.
// We parse only for items that we know about - if we come across a pair
// whose name we do not know about, we ignore the pair and go on to the next.
// There's no global list to tell us what type things are, and we don't assume.
// We don't allow setting pointers using this method.
int
GAParameterList::read(std::istream& is, GABoolean flag){
int nfound = 0;
if(n == 0) return nfound;
char buf[BUFSIZE];
char name[NAMESIZE];
int toggle = 0, count = 0, npairs = -1;
is.width(sizeof(buf)); // don't allow to overrun buffer
do{
is >> buf;
if(npairs == -1){
if(IsNumeric(buf)){
npairs = atoi(buf);
is >> buf;
}
else{
npairs = MAX_PAIRS;
}
}
if(is.eof()){
break;
}
else if(buf[0] == '#'){ // dump to end-of-line
is.get(buf, BUFSIZE); // fails on lines longer than BUFSIZE
}
else if(toggle == 0){
strcpy(name, buf);
toggle = 1;
}
else if(toggle == 1){
int found = 0;
count += 1;
toggle = 0;
for(unsigned int i=0; i<n && !found; i++){
if(strcmp(name, p[i]->fullname()) == 0 ||
strcmp(name, p[i]->shrtname()) == 0){
found = 1;
int ival;
float fval;
double dval;
switch(p[i]->type()){
case GAParameter::BOOLEAN:
case GAParameter::INT:
ival = atoi(buf);
set(name, (void*)&ival);
nfound += 1;
break;
case GAParameter::CHAR:
case GAParameter::STRING:
set(name, (void*)buf);
nfound += 1;
break;
case GAParameter::FLOAT:
fval = (float)atof(buf);
set(name, (void*)&fval);
nfound += 1;
break;
case GAParameter::DOUBLE:
dval = (double)atof(buf);
set(name, (void*)&dval);
nfound += 1;
break;
case GAParameter::POINTER:
default:
break;
}
// Move this parameter to the front of the list
// if(i > 0) {
// GAParameter *tmpptr = p[i];
// memmove(&(p[1]), &(p[0]), i * sizeof(GAParameter*));
// p[0] = tmpptr;
// }
if(i < n-1) {
//.........这里部分代码省略.........