using c++ and c standard I/O functions

Is it not a healthy practice to mix C and C++ standard I/O functions together

e.g.



string name; // this is a declared instance of the string class in C++

printf("\nPlease enter your name: ");
cin >> name;

I did something similar in a program Im designing, and used it several times across my code. The first instance worked, however the second time I called it, the program crashed on me.

Is it generally a good idea to do this ? If not, why ?

thanks

It is not a good idea to do this because they both use the same global resources and are probably not aware of each other. If either of them changes global things like file descriptors, etc. in ways the other is not aware of, it may cause unexpected results in the other, including crashes.

On the other hand it is fine to mix iostream and stdio as long as you don't use them on the same files. Since stdin and stdout are of course different, I suspect the crash you had was for reasons unrelated, but can't say this for sure without seeing the real code.