Advertisement

Different input and output methods, what's the difference?

Started by March 06, 2002 07:11 PM
4 comments, last by Shmiznac 22 years, 9 months ago
I''ve got a few old C++ books that have taught me to do input and output like this: int age; cout << "How old are you? "; cin >> age; cout << age; But now I''ve got this fancy shmancy new Visual C++ .NET book that tells me to do it like this: Console::Write("How old are you? "); String * input = Console::ReadLine(); int age = input->ToInt32(0); Console::Write(age); Which way is the "correct" way to do it? Is one way faster than the other? Thanks for trying to help a poor noob like me . Shmiznac
Shmiznac
The first is ANSI, use it.

Advertisement
So the first way (cout) is the standard way? Does that mean the first way will work in all compilers, but the other way won''t? Is one of them faster than the other?

Sorry, I know, I ask too many questions .


Shmiznac
Shmiznac
quote: Original post by Shmiznac
So the first way (cout) is the standard way?

Yes, it''s magnitudes closer to ANSI C++ than the second, which looks like .NET stuff, which there''s no reason you should be learning or using yet; especially if you want to learn C++.
quote: Original post by Shmiznac
Does that mean the first way will work in all compilers, but the other way won''t?

Basically, yes.
quote: Original post by Shmiznac
Is one of them faster than the other?

Who cares? It''s console output, after all.

I assume that the second one is using the classes from the .NET framework. Now this is fine if you are writing a .NET app and targeting the .NET platform, but if you do indeed want it to work on all compilers, use the first. As for speed, I don''t imagine there is too much of a difference.
ReactOS - an Open-source operating system compatible with Windows NT apps and drivers
Thanks guys, that''s exactly what I wanted to know . I guess Microsoft is writing .NET books that use that funky way of I/O in order to corrupt the minds of n00bs like me into using their .NET features.


Shmiznac
Shmiznac

This topic is closed to new replies.

Advertisement