Lynda.com C++ Training Question

I am interested in learning C++ basics and then focus on Unreal engine 4 development with C++. I started to watch the lynda.com series after reading apart of my game development with C++ book and I was wondering if anyone could tell me which is a more correct (based on the industry standards) to printing to console?

In the book it uses the preprocessor directive iostream with cout but with Lynda.com they use cstdio and printf.

If my memory isn't failing me i believe that cstdio is from C and Im just wondering if I being taught something useful with Lynda.com or should I stick with iostream? I do know from my research that cstdio is a bit limited.

I guess im just wonderign which to use to start learning C++ and if there was a better resource than using Lynda.com or to just stay away from their courses on C++
My computer science teacher who works industry always had us pass a ( ostream& out ) to a class constructor and then we would instantiate cout from main like so...

myFooControler aObject(cout);

Then we would either overload << or just call it using . or ->.

His argument was to try and abstract the output of our programs in order to allow our classes / code send output where ever we decide later, like standard out for debugging or to the screen of custom class in a API like unreal for instance.

I am not sure if I am explaining this very good, I hope that makes sense.
Last edited on
Don't know why lynda.com uses C I/O functions as opposed to cout and cin. Being familiar with printf can be useful though.
My computer science teacher who works industry always had us pass a ( ostream& out ) to a class constructor and then we would instantiate cout from main like so...

You can't decide what output you want later on with your teachers method so that's stupid, you could just overload operator<< for ostream and your class...
1
2
3
4
5
std::ostream& operator<<(std::ostream& os, const Foo& foo)
{
    os << foo.data(); // something like this
    return os;
}


... and then you could use it wherever you want:
1
2
3
Foo f;
std::cout << f;
std::ostream("test.txt") << f;


(you could do similar things with istream)

@Cody0023
I guess im just wonderign which to use to start learning C++ and if there was a better resource than using Lynda.com or to just stay away from their courses on C++
the iostream library is typesafe so if you don't want to play around with the binary representation of types stick with iostream because it's safer and more flexible and prettier and just better, maybe a little bit slower but that should'nt be a concern since your choise in algorithms and containers should dominate the performance of your program.
In addition to that you can just overload operators which makes it more readable as well.
Last edited on
Use the iostream library because it's typesafe.
You can't decide what output you want later on with your teachers method

Maybe not when using printf(), but if you use fprintf() then you get the same ability.

the iostream [is] maybe a little bit slower but that should'nt be a concern since your choise in algorithms and containers should dominate the performance of your program.

Disks are about a MILLION times slower than CPUs (milliseconds vs. nanoseconds), so unless a program's algorithms are really bad, I/O will dominate performance. Sadly, a program's algorithms are frequently really bad. :)

Once thing I've noticed on the forum is that beginners seem to be taught to use endl to end lines when outputting with iostream. The problem with endl is that it flushes the stream, which might very well cause one of those millisecond delays. Use '\n' to end a line whenever possible to avoid this.
Topic archived. No new replies allowed.