本文整理汇总了C++中stringstream::good方法的典型用法代码示例。如果您正苦于以下问题:C++ stringstream::good方法的具体用法?C++ stringstream::good怎么用?C++ stringstream::good使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stringstream
的用法示例。
在下文中一共展示了stringstream::good方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: readCombinaison
bool NodeFactory::readCombinaison(stringstream &sPath, U32 maxPosition, U32 &position, U8* &pCombinaisons) noexcept{
bool bResult = true;
if (position == 0)//if there was no previous search
position = sPath.str().find_first_of('[');
else
position = sPath.str().find_first_of('[', position + 1);
if (static_cast<size_t> (position) != string::npos) {
char separator = '[';
cerr << "fillNodeInit: found [" << endl;
sPath.seekg(static_cast<size_t> (position + 1), ios::beg);
for (U32 combiItem = 0; combiItem < maxPosition; combiItem++) {
if (sPath.good()) {
if (separator != ']') {//retrieve another item of the combinaison
U32 temp;
sPath >> temp;
*pCombinaisons = static_cast<U8> (temp);
pCombinaisons++;
cerr << "position:" << position << endl;
cerr << "[" << temp << "]";
cerr << "�" << combiItem << "," << maxPosition << "�" << endl;
}
else //separator == ']'
{//combinaison completed too soon, all items of the combinaison are not retrieved
bResult = false;
break;
}
} else {//incomplete combinaison
示例2: parse_network_result_output
void NetworkRenderer::parse_network_result_output(stringstream &recv_ss) {
int packet_number;
recv_ss>>packet_number;
recv_ss.get();
std::vector<Color> result;
while(recv_ss.good()) {
int ir,ig,ib;
ir=recv_ss.get();
ig=recv_ss.get();
ib=recv_ss.get();
float r,g,b;
r=(float)ir/(float)255;
g=(float)ig/(float)255;
b=(float)ib/(float)255;
if(recv_ss.good()) {
Color c(r,g,b);
result.push_back(c);
}
}
int height;
int act_height=CLIENT_TASK_LINES*packet_number;
if(act_height+CLIENT_TASK_LINES>rendering_height) {
height=rendering_height-act_height;
} else {
height=CLIENT_TASK_LINES;
}
// display.add_surface(0,act_height,rendering_width,height,result);
std::vector<Color> realresult;
for(int i=0;i<Settings::getAsInt("window_width")*5;i++) {
realresult.push_back(Color(1,0,0));
}
display.add_line_group(0,act_height,realresult);
Logger::log()<<"Received "<<packet_number<<" of "<<result.size()<<" (height="<<act_height<<")"<<std::endl;
// display.refresh_part_display_timecheck();
}
示例3: solveTheProblem
/************************************************************************
* solveTheProblem *
* Assumes the equations and variables have already been entered *
* solves the problem, writing the solution in TEMP_FILE, *
* including the tags and problem statements if the problem was *
* not completely solved. *
* Then it opens the file for reading, and returns the first line *
* [does not close file] *
************************************************************************/
const char* solveTheProblem() {
int k;
if (isFirst) throw string("solveTheProblem called before initialization");
try {
// reset the buffer to be empty
resultBuffer.str(string());
if(resultBuffer.good()) {
numsols->assign(canonvars->size(),HUGE_VAL);
if (solveeqs(resultBuffer)) {
// should we do checking of solution here?
bool discrep = false;
for (k = 0; k < canoneqf->size(); k++) {
if (checksol((*canoneqf)[k],numsols,RELERR) > 1) {
if (!discrep) {
resultBuffer << "<DISCREPANCIES>" << endl;
discrep = true;
}
resultBuffer << (*canoneqf)[k]->getInfix() << endl;
}
} // loop over equations to check
dimchkeqf(resultBuffer);
// end of "should we do checking of solution here?"
}
}
else throw string("unable to create solution buffer");
}
catch (string message) { throw message; }
catch (...) { throw string("solveTheProblem went boom!!"); }
// this would be a good place to insert checksol ? or after returning
// solution, in solveMoreOfTheProblem ?
try {
resultBuffer.clear();
resultBuffer.seekg(0);
int tk;
try { tk = resultBuffer.eof(); }
catch (...) { throw string("eof?!?"); }
if (! tk) {
string t;
try { t = getaline(resultBuffer); }
catch (...) { throw string("getaline fails???"); }
try { sprintf(lzbfr, "%s", t.c_str()); }
catch(...) { throw string("copy is wrong??"); }
return lzbfr;
}
else return error[4];
}
catch (string message) { throw message; }
catch (...) { throw string("Read went bad!!"); }
return error[3];
}
示例4: readElement
void readElement(string& readed, stringstream &str) {
int c;
do {
c = str.get();
if (c != ';') {
if ((readed.length() != 0) || ((c != 13) && (c != 10))) {
if (str.good()) {
char str[2];
str[0] = c;
str[1] = '\0';
readed += str;
} else {
break;
}
}
}
} while (c != ';');
}
示例5: ReadLine
int ResourceParser::ReadLine(stringstream& p_stream, vector<string>& p_tokens, int& p_line)
{
p_tokens.clear();
size_t i = 0;
int result = READ_CHUNK;
char buf[LINE_BUFFER_SIZE];
for (; i < LINE_BUFFER_SIZE; ++i)
{
p_stream.get(buf[i]);
if (!p_stream.good() || ('\n' == buf[i]))
{
buf[i] = '\0';
++p_line;
break;
}
if (BLOCK_OPENING_BRACES.c_str()[0] == buf[i])
{
result = READ_BLOCK_OPEN;
buf[i + 1] = '\0';
break;
}
if (BLOCK_CLOSING_BRACES.c_str()[0] == buf[i])
{
result = READ_BLOCK_CLOSE;
buf[i + 1] = '\0';
break;
}
}
char* line = (char*)stringUtils::Trim(buf);
if ((nullptr == line) || (strlen(line) == 0) || (LINE_COMMENT == line[0]))
return READ_EMPTY;
stringUtils::Tokens(line, DELIMITERS, p_tokens);
return result;
}
示例6: fillBuffer
uint32_t QueryableNetstringsDeserializerABCF::fillBuffer(istream& in, stringstream& buffer) {
char _c = 0;
uint32_t bytesRead = 0;
// Peek Container's header: 2 bytes (0xABCF) followed by maximum 8 bytes (uint64_t) length of payload information.
uint32_t bytesToRead = sizeof(uint16_t) + sizeof(uint64_t);
// Read Container header + size of payload.
while (in.good() && (bytesToRead > 0)) {
// Read next byte.
in.read(&_c, sizeof(char));
bytesToRead--; bytesRead++;
// Add new byte at the end of the buffer.
buffer.write(&_c, sizeof(char));
}
// Decode Container's magic number.
uint16_t magicNumber = 0;
buffer.read(reinterpret_cast<char*>(&magicNumber), sizeof(uint16_t));
magicNumber = ntohs(magicNumber);
if (magicNumber == 0xABCF) {
// Decode size of payload (encoded as varint).
uint64_t value = 0;
uint8_t size = 0;
{
while (buffer.good()) {
char c = 0;
buffer.read(&c, sizeof(char));
value |= static_cast<unsigned int>( (c & 0x7f) << (0x7 * size++) );
if ( !(c & 0x80) ) break;
}
// Decode as little endian like in Protobuf's case.
value = le64toh(value);
}
bytesToRead = (value // This is the length of the payload.
- (sizeof(uint64_t) // We have already read this amount of bytes while peeking the header.
- size) // This amount of bytes was consumed to encode the length of the payload in the varint field.
)
+ 1; // And we need to consume the final ','.
// Add the data at the end of the buffer.
buffer.seekg(0, ios_base::end);
// Read remainder of the container.
while (in.good() && (bytesToRead > 0)) {
// Read next byte.
in.read(&_c, sizeof(char));
bytesToRead--; bytesRead++;
// Add new byte at the end of the buffer.
buffer.write(&_c, sizeof(char));
}
// Move read pointer to the beginning to read container.
buffer.seekg(0, ios_base::beg);
}
return bytesRead;
}