Using printf instead of cout

Hi there. When I’m using printf instead of cout I’m getting weird values instead of the string I give as parameter. Why is this the case, and how can i fix it so I can use printf instead of cout?

To my knowledge printf is a C function. Yes, you can use it in C++, but its not “safe” so to say, because you are more compelled of making a syntax error. On the other hand cout, comes with less of a risk of a syntax errors, thanks to the integrated libraries. Secondly cout and printf have completely different syntaxes! Also you can’t use printf with cin, that’s the error i think that you are making and thats why you get those strange characters in return. You use printf with scanf, but scanf being a C function doesn’t know what class or string is, therefor its really hard to work(not impossible though), but its really wasteful to go out of your way to use printf in this particular instance. Hope that helped. Good luck mate!

3 Likes

Privacy & Terms