1 / 9
Jan 2011

I have a quick question about inputs that applies to almost any problem here (I'm a real newbie when it comes to C++...):
Is it possible to use cin and cout when solving these problems? If not, could someone explain to me a preferable way?

Thanks,
Carnax

You can use them, but they are very slow, so for any problem with a reasonable amount of input you will probably exceed the time limit even if your algorithm is correct. You should use C-style input/output methods instead - ie printf and scanf.

Okay, thanks, but I have one more question (hopefully only one). Could you (or anyone) describe to me how to use scanf & printf? I looked it up at cplusplus.com, but it confused me. Just an example, maybe using TEST would help.

-Carnax

Wait, one more question:
How do you get multiple inputs from one line of code (as there are in most problems?)

Thanks again,
Carnax

Okay, I get that, but what about multiple inputs on one line?

Thanks,
Carnax

Okay, hopefully this is my last question:
Can you give an example for how to print (using printf, obviously), an integer variable named a?

Thanks,
Carnax

1 month later

cout & cin are part of the iostream interface for input and output. They are an ostream object and an istream object, respectively. They use the overloaded << operator to output any object, based on its type and the various flags set by manipulators.

Suggested Topics

Topic Category Replies Views Activity
C and C++ 0 14 6d

Want to read more? Browse other topics in C and C++ or view latest topics.