Sign in to follow this  
Storyyeller

Mixing stdio and iostream

Recommended Posts

I usually use C++ stream objects like cout and cin for conole I/O, but the library I started using requires C style I/O. Is it ok to mix them? For example, I currently have something like
        cout << "Enter a big number.\n";
        mpz_inp_str( n, stdin, 0);
        cout << "You entered\n";
        mpz_out_str( stdout, 10 , n);
        cout << "\nIn Hexadeciaml, that is\n0x";
        mpz_out_str( stdout, -16 , n);
        cout << "\n";

It appears to work, but that isn't always a guarantee that it will in the future.

Share this post


Link to post
Share on other sites
Quote:
Original post by Storyyeller
Is it ok to mix them?


I think so, it may not make for pretty code, but there shouldn't be any execution problems, cin, cout and cerr encapsulate stdin, stdout and stderr, so it is not like you're really having separate streams.

Share this post


Link to post
Share on other sites
Quote:
Original post by Kwizatz
Quote:
Original post by Storyyeller
Is it ok to mix them?
I think so, it may not make for pretty code, but there shouldn't be any execution problems, cin, cout and cerr encapsulate stdin, stdout and stderr, so it is not like you're really having separate streams.
It is guaranteed to work, AFAIK. However, mixing stdio and iostreams can have unfortunate effects on the performance of the iostreams, because they have to do extra work to keep the buffering correct.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this