• Advertisement
Sign in to follow this  

Mixing stdio and iostream

This topic is 3139 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Sign in to follow this  

  • Advertisement