Jump to content
  • Advertisement
Sign in to follow this  
mrtie_dye

old headers

This topic is 4725 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 am learning SDL from a tutorial, and the tutorial uses the old headers such as stdlib.h. I am trying to convert everything over to the newer headers such as iostream. I know how to use cout, cin, ofstream, etc. But the tutorial uses printf for error messages and such. The nice thing about this is it automatically creates a file called stdout.txt and dumps the errors in there. Is there a way to get cout (or anything else for that matter) to do this without having to create an ofstream and open a file? Thanks for any help. EDIT: Almost forgot. What about atexit()? What was it replaced by? EDIT: What use are the ansi standard headers if I can't use them together? For instance, if I create an ifstream called file, and a string called filename, I can't do this... file.getline(filename,100); Now, I have to spend the rest of the morning tracking down a way to convert the string into something getline can handle. Any suggestions are welcome. [Edited by - mrtie_dye on June 17, 2005 4:37:47 AM]

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by mrtie_dye
I am learning SDL from a tutorial, and the tutorial uses the old headers such as stdlib.h. I am trying to convert everything over to the newer headers such as iostream.

I know how to use cout, cin, ofstream, etc. But the tutorial uses printf for error messages and such. The nice thing about this is it automatically creates a file called stdout.txt and dumps the errors in there.

Is there a way to get cout (or anything else for that matter) to do this without having to create an ofstream and open a file?

Thanks for any help.

EDIT: Almost forgot. What about atexit()? What was it replaced by?

EDIT: What use are the ansi standard headers if I can't use them together? For instance, if I create an ifstream called file, and a string called filename, I can't do this...

file.getline(filename,100);

Now, I have to spend the rest of the morning tracking down a way to convert the string into something getline can handle. Any suggestions are welcome.


AFAIK, atexit() has not been replaced. Moreover, stdlib.h is not an old header, it is not just part of the C++ standard - which is not very important since SDL is written in C. If you want to write a standard compliant C++ sample, you can just use <cstdlib>: it includes stdlib.h, put everything in the std namespace, and is a C++ standard header.

Anayway, translating C to C++ is a good idea: it will improve your knowledge of both standard libraries, and it can't be bad.

Regards,

Share this post


Link to post
Share on other sites
Quote:
Original post by mrtie_dye
I am learning SDL from a tutorial, and the tutorial uses the old headers such as stdlib.h. I am trying to convert everything over to the newer headers such as iostream.


Generally, for old C++ headers (like iostream.h), just drop the .h.
For old C headers (like stdlib.h or ctype.h), also append a 'c' at the beginning. Thus in your case, the new header is <cstdlib>. And remember that stuff will then be placed into namespace std. :)

Quote:
I know how to use cout, cin, ofstream, etc. But the tutorial uses printf for error messages and such. The nice thing about this is it automatically creates a file called stdout.txt and dumps the errors in there.

Is there a way to get cout (or anything else for that matter) to do this without having to create an ofstream and open a file?


Presumably SDL is already doing something along the same lines, since plain old printf would normally write to the console rather than a file. :)

Try just using cout; failing that, there is probably some magic (sync_with_stdio?) involved that someone else will be able to help you with.

Quote:

EDIT: Almost forgot. What about atexit()? What was it replaced by?


atexit() is still there. But really, what do you need it for? o_O

Quote:

EDIT: What use are the ansi standard headers if I can't use them together? For instance, if I create an ifstream called file, and a string called filename, I can't do this...

file.getline(filename,100);

Now, I have to spend the rest of the morning tracking down a way to convert the string into something getline can handle. Any suggestions are welcome.


(Edit: completely misread. Doubt if anyone saw the original though :/ )

Use the free-function version, std::getline(istream&, std::string&). It will take advantage of the string's automatic resizing by not requiring you to limit your line length. :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!