English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Ok, so i was looking at this code, and I already know the function cin, but I saw it with .ignore() or something else. What does it mean when you put a . and then something else? The ones I saw were cin.clear(); cin.ignore(); and cin.fail(), I want to know these but also in general I didn't know you could put cin with something esle...

2007-12-26 02:43:47 · 4 answers · asked by Anonymous in Computers & Internet Programming & Design

So, ignore() is like a function in cin? Is there like a list I can see that says all of them?

2007-12-26 06:29:42 · update #1

4 answers

Everyone worded this kind of weird.

cin is a Class inside of C++ (at least in the one you are working on).

A class is basically like a structure, with functions and variables in it.

say you had a class CMyClass

class CMyClass
{
private:
int privateInt; // a variable only this class can access


public:
int publicInt; // a variable anything can access

CMyClass ( void ) // constructor
{ // initialize your variables
}

~CMyClass() {} //destructor, if you needed to free mem

int load ( int c )
{
// load something
privateInt = c;
return c;
}
}




Now you can create a copy of this class:

CMyClass cin;

cin.load( 7 );

If this was a pointer you could have done this:
CMyClass *cin;

cin = new CMyClass();
cin->load( 7 );

(you access class functions through pointers differently)

2007-12-26 04:59:57 · answer #1 · answered by Adopted 3 · 0 0

The basic principle in an object oriented language like C++ is 'object(dot)property', or object.property.
So, when you see something like
cin.clear(), it basically means that cin is an actual object, and that 'clear' is one of its methods - as are ignore, fail, etc. This will help you alot in the future, because whenever you see something like

rs.FindFirst

in code, you will know that 'rs' is an object of some kind, and 'FindFirst' is a method of that object. Sometimes the objects are built in objects, other times they are user-defined. But just knowing that they are objects can help alot. Good luck to you.

2007-12-26 10:50:51 · answer #2 · answered by Anonymous · 1 0

cin is an object and has several methods. You mention three of them...

cin.ignore(); // throw away the next char on the stream
cin.fail(); // returns 1 if you asked cin to do something that it can't, such as convert a char to int
cin.clear(); // clears the fail state if failure occurs

2007-12-26 10:49:25 · answer #3 · answered by jgoulden 7 · 0 0

both the above answers are what did i mean to say:-)

2007-12-26 11:15:52 · answer #4 · answered by slimshadym23 2 · 0 0

fedest.com, questions and answers