Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

cin input limitation

Name: Anonymous 2008-09-02 6:52

so I'm a c++ retard, how do I limit cin to only take int inputs? just ignoring strings would be nice.

Name: Anonymous 2008-09-02 7:06

>>1
don't use cin.

Name: Anonymous 2008-09-02 8:02

Use a token iterator.

Name: Anonymous 2008-09-02 8:12

FUCK OFF!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Name: Anonymous 2008-09-02 9:44

Wow, you guys are so helpful. No wonder nobody talks about programming here.

Name: Anonymous 2008-09-02 10:14

Nobody talks about programming because we don't have to. We already know everything and you're just retarded.

Name: 3 2008-09-02 10:19

>>5
You must be new here so let me be the first to welcome you to the world of internet.

But FFS if you want help an ad hominem won't convince anyone to do so.

PS. Look for a "Completely reusable tokenizer" from "Thinking in C++ vol.2".

Name: Anonymous 2008-09-02 10:33

>>5
Would you walk into a literature club meeting and ask how to find the subject of a sentence? Please don't disturb our gentlemanly pursuits with your commoner ramblings, we are busy drinking tea and reading SICP. (While wearing our fezzes and monocles.)

Name: Anonymous 2008-09-02 11:40

Try something like so:

do {
   if (!cin) {
      cin.flush();
      cin.clear();
   }
   cint >> integer;
} while (!cin);

>>8
Why not? They should then show the fuckin idiot why it is the literature club.

Name: Anonymous 2008-09-02 12:02

Version .9:

char shitbuf [1024];
int integer

do {
   if (cin.fail()) {
      cin.getline(shitbuf, 1024, '\n');
      cin.clear();
   }
   cin >> integer;
} while (cin.fail());

Name: Anonymous 2008-09-02 14:39

def IntInput():
    while True:
        try:
            yield int(raw_input())
        except ValueError:
            pass
        except EOFError:
            raise StopIteration

Name: Anonymous 2011-02-04 14:12


Don't change these.
Name: Email:
Entire Thread Thread List