Sponsored Content
Full Discussion: is this a bug of g++?
Top Forums Programming is this a bug of g++? Post 302503609 by jlliagre on Friday 11th of March 2011 05:00:58 AM
Old 03-11-2011
My understanding is you need to flush the "bad" data.
cin.clear() doesn't clear the buffer, it clears error conditions.
Code:
#include<iostream>

using namespace std;

int main()
{
    int val;
    string bad;

    while(cin>>val,!(cin.eof()))
    {
        if(cin.fail())
        {
            cerr<<"bad data,try again"<<endl;;
            cin.clear();
            cin>>bad;
            continue;
        }
        else if(cin.good())
        {
            cerr<<"you entered :"<<val<<endl;
            break;
        }
    }
}

 

8 More Discussions You Might Find Interesting

1. Programming

Bug has developed

Guys there is another bug that has developed.........now messaged above 6 bytes are trimmed and echoed back to client.After the first message the echo is not regular.I have put a loop in both client and server to check for closing.Moreover for connection close i also need to put another clause that... (3 Replies)
Discussion started by: arjunjag
3 Replies

2. Post Here to Contact Site Administrators and Moderators

Have I found a bug?

When searching for new posts, I see that my voting in one of the polls counts as a 'new post'. However, while the '<blah> minutes ago' entry updates correctly, the 'by <username>' is the last user to actually post a comment in the poll instead. Result: Poll: vB Guest Book 39... (4 Replies)
Discussion started by: Smiling Dragon
4 Replies

3. UNIX for Advanced & Expert Users

logrotate bug?

I have been mailing myself logs for a while, but just ran into a problem because of a process that cannot HUP its log. (I realize thats why they implemented the "copytruncate" option in the first place) When I use logrotate with "copytruncate" and "compress" there is a problem. The "myScript"... (0 Replies)
Discussion started by: jjinno
0 Replies

4. Shell Programming and Scripting

Is it a bug ..?

Hi All, I am using Red Hat Linux on my servers. The problem that I am facing is, sometimes the /opt usage on the server shows used percentage as 100% , when actually it is simply 20%. When I reboot the system, it comes back to 20%.Is this a bug in the system or my settings have gone wrong... (1 Reply)
Discussion started by: nua7
1 Replies

5. AIX

bug in 43 ???

xxxxserver# lsattr -El inet0 | grep 255.240.0.0,32.224.0.0,32.78.120.254 | grep '.40' route net,-hopcount,1,-netmask,255.240.0.0,32.224.0.0,32.78.120.254 How this is possible? (1 Reply)
Discussion started by: itik
1 Replies

6. UNIX for Dummies Questions & Answers

where's the bug?

#!/bin/bash if then #echo "infinite loop" exit 0 fi when I run this file I get the following error: ./test_infinite_loop: line 5: syntax error near unexpected token `fi' ./test_infinite_loop: line 5: `fi' :confused: (4 Replies)
Discussion started by: jon80
4 Replies

7. Shell Programming and Scripting

How to fix this bug?

Hi gurus, I have script as below: #!/bin/ksh while : do cat /dev/null > srcfile exit_time=`TZ=GMT-20 date +%Y%m%d1950` cur_time=`date +%Y%m%d%H%M` flag=1 if ; then ... (7 Replies)
Discussion started by: ken6503
7 Replies

8. UNIX for Advanced & Expert Users

A $(( expression )) bug?

This is for the big guns... I have been modifying AudioScope.sh to bring it inline with more current practices. I hit a bug which IS not present in the original code but was after modification. Shell check first:- #!/bin/sh txt="1234567890" echo "$(( $txt ))" echo "$(( ${#txt} - 1 ))" echo... (17 Replies)
Discussion started by: wisecracker
17 Replies
FBB::StringLine(3bobcat)					  Line extractor					  FBB::StringLine(3bobcat)

NAME
FBB::StringLine - extracting lines using operator>> SYNOPSIS
#include <bobcat/stringline> DESCRIPTION
The standard operator>>(std::istream &, std::string &) string extracion operator extracts the first `word' from a stream. In cases where the intent it to extract lines from the stream this operator cannot be used, but getline(std::istream &, std::string &) is usually called. However, getline is not called by many tools of generic algorithms, like the istream_iterator. The class (actually: struct) StringLine was simply derived from std::string, and defines its own operator>>, reading the next line from the specified std::istream. NAMESPACE
FBB All constructors, members, operators and manipulators, mentioned in this man-page, are defined in the namespace FBB. INHERITS FROM
std::string CONSTRUCTORS
StringLine is an empty shell around std::string. It does not explicitly define constructors. The default and copy constructors are avail- able. OVERLOADED OPERATOR
o std::istream &operator>>(std::istream &in, StringLine &str): The extraction operator returns the next line on in in str, calling getline(std::istream &, std::string &). MEMBER FUNCTIONS
All members of std::string are available, as FBB::StringLine inherits from these classes. EXAMPLE
The following example extracts all lines from std::cin and adds them to the std::vector<std::string> lines: #include <iostream> #include <algorithm> #include <iterator> #include <vector> #include <bobcat/stringline> using namespace std; using namespace FBB; int main() { vector<string> lines; copy( istream_iterator<StringLine>(cin), istream_iterator<StringLine>(), back_inserter(lines) ); } FILES
bobcat/stringline - defines the class interface and operator>>. There are StringLine object files in the Bobcat library, so linking to Bobcat when using StringLine is not necessary. SEE ALSO
bobcat(7) BUGS
None Reported. DISTRIBUTION FILES
o bobcat_3.01.00-x.dsc: detached signature; o bobcat_3.01.00-x.tar.gz: source archive; o bobcat_3.01.00-x_i386.changes: change log; o libbobcat1_3.01.00-x_*.deb: debian package holding the libraries; o libbobcat1-dev_3.01.00-x_*.deb: debian package holding the libraries, headers and manual pages; o http://sourceforge.net/projects/bobcat: public archive location; BOBCAT
Bobcat is an acronym of `Brokken's Own Base Classes And Templates'. COPYRIGHT
This is free software, distributed under the terms of the GNU General Public License (GPL). AUTHOR
Frank B. Brokken (f.b.brokken@rug.nl). libbobcat1-dev_3.01.00-x.tar.gz 2005-2012 FBB::StringLine(3bobcat)
All times are GMT -4. The time now is 12:45 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy