本文整理汇总了C++中std::istream::get方法的典型用法代码示例。如果您正苦于以下问题:C++ istream::get方法的具体用法?C++ istream::get怎么用?C++ istream::get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::istream
的用法示例。
在下文中一共展示了istream::get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
void Polynomial<T>::input(std::istream &in)
{
T coef;
int data;
in.clear();
in>>coef>>data;
while(in.good())
{
operator+=(Polynomial(coef,data));
in>>coef>>data;
}
in.clear();
in.get();
}
示例2: isGzippedStream
/// Determine whether the given stream is gzipped.
bool RibInputBuffer::isGzippedStream(std::istream& in)
{
bool isZipped = false;
std::istream::int_type c = in.get();
// Check whether the magic number matches that for a gzip stream
const std::istream::int_type gzipMagic[] = {0x1f, 0x8b};
if(c == gzipMagic[0])
{
if(in.peek() == gzipMagic[1])
isZipped = true;
}
in.unget();
return isZipped;
}
示例3: isGzip
static bool isGzip(std::istream & in)
{
int const b0 = in.get();
if ( b0 < 0 )
return false;
int const b1 = in.get();
if ( b1 < 0 )
{
in.clear();
in.putback(b0);
return false;
}
in.clear();
in.putback(b1);
in.putback(b0);
return b0 == libmaus2::lz::GzipHeaderConstantsBase::ID1 &&
b1 == libmaus2::lz::GzipHeaderConstantsBase::ID2;
}
示例4: readUrl
void HTMLForm::readUrl(std::istream& istr)
{
static const int eof = std::char_traits<char>::eof();
int fields = 0;
int ch = istr.get();
while (ch != eof)
{
if (_fieldLimit > 0 && fields == _fieldLimit)
throw HTMLFormException("Too many form fields");
std::string name;
std::string value;
while (ch != eof && ch != '=' && ch != '&')
{
if (ch == '+') ch = ' ';
name += (char) ch;
ch = istr.get();
}
if (ch == '=')
{
ch = istr.get();
while (ch != eof && ch != '&')
{
if (ch == '+') ch = ' ';
value += (char) ch;
ch = istr.get();
}
}
std::string decodedName;
std::string decodedValue;
URI::decode(name, decodedName);
URI::decode(value, decodedValue);
add(decodedName, decodedValue);
++fields;
if (ch == '&') ch = istr.get();
}
}
示例5: readMultipart
void HTMLForm::readMultipart(std::istream& istr, PartHandler& handler)
{
static const int eof = std::char_traits<char>::eof();
MultipartReader reader(istr, _boundary);
while (reader.hasNextPart())
{
MessageHeader header;
reader.nextPart(header);
std::string disp;
NameValueCollection params;
if (header.has("Content-Disposition"))
{
std::string cd = header.get("Content-Disposition");
MessageHeader::splitParameters(cd, disp, params);
}
if (params.has("filename"))
{
handler.handlePart(header, reader.stream());
// Ensure that the complete part has been read.
while (reader.stream().good()) reader.stream().get();
}
else
{
std::string name = params["name"];
std::string value;
std::istream& istr = reader.stream();
int ch = istr.get();
while (ch != eof)
{
value += (char) ch;
ch = istr.get();
}
add(name, value);
}
}
}
示例6: nextToken
void JSSPageReader::nextToken(std::istream& istr, std::string& token)
{
token.clear();
int ch = istr.get();
if (ch != -1)
{
if (ch == '<' && istr.peek() == '%')
{
token += "<%";
ch = istr.get();
ch = istr.peek();
switch (ch)
{
case '%':
case '@':
case '=':
ch = istr.get();
token += (char) ch;
break;
case '!':
ch = istr.get();
token += (char) ch;
if (istr.peek() == '!')
{
ch = istr.get();
token += (char) ch;
}
break;
case '-':
ch = istr.get();
token += (char) ch;
if (istr.peek() == '-')
{
ch = istr.get();
token += (char) ch;
}
break;
}
}
else if (ch == '%' && istr.peek() == '>')
{
token += "%>";
ch = istr.get();
}
else token += (char) ch;
}
}
示例7: style
// style prompts for and accepts the style from input stream is
//
bool style(std::istream& is, char& s) {
bool rc = false, ok = false;
char c;
do {
std::cout << " EAN Style ('-', ' ', '\\n' or '0' to quit) : ";
c = ' ';
is.get(c);
if (is.fail()) {
is.clear();
is.ignore(2000, '\n');
std::cerr << " Invalid input. Try again.\n";
} else if (c != '-' && c != ' ' && c != '\n' && c != '0') {
is.ignore(2000, '\n');
std::cerr << " Invalid Character. Try again.\n";
} else if (c == '0') {
if (is.get() != '\n') {
is.ignore(2000, '\n');
std::cerr << " Trailing Characters. Try Again.\n";
} else {
ok = true;
}
} else if (c == '\n') {
ok = true;
s = '\0';
rc = true;
} else if (is.get() != '\n') {
is.ignore(2000, '\n');
std::cerr << " Trailing Characters. Try Again.\n";
} else if (c == '-' || c == ' ') {
ok = true;
s = c;
rc = true;
}
} while (!ok);
return rc;
}
示例8: configParExceptionParseError
/** returns inner content of a quoted string
* Matches pattern "[^"]*"\s* and returns matching part without quotes
*
*/
std::string
configparBase::parse_quoted_string(std::istream &in) {
if ( in.get() != '"' )
throw configParExceptionParseError("string doesn't start with a quotation mark");
bool escape = false;
std::string tmp;
char c;
while ( in.get(c) ) {
if ( escape ) {
if ( c == '\\' || c == '"' )
tmp += c;
else
throw configParExceptionParseError("invalid escape sequence");
escape = false;
}
else {
if ( c == '"' )
break;
else if ( c == '\\' )
escape = true;
else
tmp += c;
}
}
// we should be on the closing quotation mark
if ( c != '"' )
throw configParExceptionParseError("unterminated string");
skip_rest_of_line(in);
return tmp;
}
示例9: GetField
bool GetField(std::istream &is, std::string &name, std::string &value)
{
name.resize(0); // GCC workaround: 2.95.3 doesn't have clear()
is >> name;
if (name.empty())
return false;
if (name[name.size()-1] != ':')
SignalTestError();
name.erase(name.size()-1);
while (is.peek() == ' ')
is.ignore(1);
// VC60 workaround: getline bug
char buffer[128];
value.resize(0); // GCC workaround: 2.95.3 doesn't have clear()
bool continueLine;
do
{
do
{
is.get(buffer, sizeof(buffer));
value += buffer;
}
while (buffer[0] != 0);
is.clear();
is.ignore();
if (!value.empty() && value[value.size()-1] == '\r')
value.resize(value.size()-1);
if (!value.empty() && value[value.size()-1] == '\\')
{
value.resize(value.size()-1);
continueLine = true;
}
else
continueLine = false;
std::string::size_type i = value.find('#');
if (i != std::string::npos)
value.erase(i);
}
while (continueLine);
return true;
}
示例10: if
// Parses a string serialized by serializeJsonStringIfNeeded.
static std::string deSerializeJsonStringIfNeeded(std::istream &is)
{
std::ostringstream tmp_os;
bool expect_initial_quote = true;
bool is_json = false;
bool was_backslash = false;
for(;;)
{
char c = is.get();
if(is.eof())
break;
if(expect_initial_quote && c == '"')
{
tmp_os << c;
is_json = true;
}
else if(is_json)
{
tmp_os << c;
if(was_backslash)
was_backslash = false;
else if(c == '\\')
was_backslash = true;
else if(c == '"')
break; // Found end of string
}
else
{
if(c == ' ')
{
// Found end of word
is.unget();
break;
}
else
{
tmp_os << c;
}
}
expect_initial_quote = false;
}
if(is_json)
{
std::istringstream tmp_is(tmp_os.str(), std::ios::binary);
return deSerializeJsonString(tmp_is);
}
else
return tmp_os.str();
}
示例11:
static std::string goto_first_of(std::istream& s, const std::string& str)
{
std::string result;
char c;
while (s.get(c))
{
if (str.find(c) != std::string::npos)
{
break;
}
result += c;
}
return result;
}
示例12: read_with_limit
void read_with_limit(
std::istream& in,
std::string& buffer,
int delim = '\n'
)
{
using namespace std;
const size_t max = 16*1024;
buffer.clear();
buffer.reserve(300);
while (in.peek() != delim && in.peek() != EOF && buffer.size() < max)
{
buffer += (char)in.get();
}
// if we quit the loop because the data is longer than expected or we hit EOF
if (in.peek() == EOF || buffer.size() == max)
throw http_parse_error("HTTP field from client is too long", 414);
// Make sure the last char is the delim.
if (in.get() != delim)
{
in.setstate(ios::badbit);
buffer.clear();
}
else
{
// Read the remaining delimiters
if (delim == ' ')
{
while (in.peek() == ' ')
in.get();
}
}
}
示例13: readHuffmanHeader
std::map<char, long long> readHuffmanHeader(std::istream &inFile, int *validBitsLastByte) {
long long length, frequency;
char space, character, space2, algorithm;
map<char, long long> char_freq;
inFile >> skipws;
inFile >> (*validBitsLastByte);
if (DEBUG) cout << " + validBitsLastByte: " << *validBitsLastByte <<endl;
inFile >> length;
if (DEBUG) cout << " + length: " << length << endl;
inFile.get(space);
if (DEBUG) cout << " - It was suppose to be a space: [" << space << "]\n";
for (int i = 0; i < length; i++) {
inFile.get(character);
inFile.get(space);
inFile >> frequency;
inFile.get(space2);
if (DEBUG) cout << "character: " << character << ", space: "<< space << ", frequency: "<< frequency << ", space2: " << space2 <<endl;
if (DEBUG) cout << "char_freq["<<character<<"] : " << frequency << endl;
char_freq[character] = frequency;
}
return char_freq;
}
示例14:
void
PinConfigInfoPacket::read(
std::istream& inputStream
)
{
int pin;
int direction;
pin = inputStream.get();
if (inputStream.good() != true)
{
return;
}
myPin = (unsigned int)pin;
direction = inputStream.get();
if (inputStream.good() != true)
{
return;
}
myDirection = ((direction == 1) ? DIR_OUTPUT : DIR_INPUT);
inputStream.get();
}
示例15: putback_test_one
bool putback_test_one(std::istream& is)
{
try {
do {
char buf[chunk_size];
is.read(buf, chunk_size);
if (is.gcount() < static_cast<std::streamsize>(chunk_size))
break;
is.putback('a');
if (is.get() != 'a')
return false;
} while (!is.eof());
return true;
} catch (std::exception&) { return false; }
}