Click here to Skip to main content
15,887,329 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how can i define my own class whose object i can use to take input and output in c++ instead of using cin and cout.?

What I have tried:

i havent tried as i am not an expert at this
Posted
Updated 3-Aug-17 21:37pm

Why (the fresh hell) do you want to replace cin and cout?
As far as I know the only (portable) ways to handle console I/O are just iostreams or plain C stdio. In other words you would have to wrap cin/cout (or scanf/printf) in your own objects?
Is this what you really want? Or you need instead to define custom extraction/insertion operators for your classes?
 
Share this answer
 
Probably, you don't want to in practice: cin and cout are very flexible, and can return or accept a huge number of context dependant types: integers, floats, doubles, chars, strings ...
You would have to make your class so that it could return each of those as well, and that's a lot of work for something that won't actually make your code any more readable (and that you won't use again in a couple of weeks when your course moves from console apps to GUI ones where cin and cout aren't used at all).

I'd find a better project if it was me!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900