stupid c++, can someone help me?
here''s my problem, I have a list of objects, and I want to iterate through the list and save the objects attributes to a file. However, all the data are integers, and the output stream only accepts char arrays to write to the file. My compilier doen''t support the itoa function, and for the life of me I can''t figure out how to stream ints into the file. Can someone please help. I''ve already lost four hours of my life that I''ll never get back.
Instead of itoa() ...
int myInteger = 500;
char str[10];
sprintf(str, "%i", myInteger);
int myInteger = 500;
char str[10];
sprintf(str, "%i", myInteger);
ReactOS - an Open-source operating system compatible with Windows NT apps and drivers
It doesn''t. It helps convert integers to strings, which you can then output to the file.
ReactOS - an Open-source operating system compatible with Windows NT apps and drivers
How about you try to cast your integers element with a pointer to a char element? Try using something like:
(char*)&integerVariable
I hope it helps you.
Battle doesn''''t need a purpose, the battle is its own purpose. You don''''t ask why a field burns or a plague spreads, don''''t ask why I fight.
(char*)&integerVariable
I hope it helps you.
Battle doesn''''t need a purpose, the battle is its own purpose. You don''''t ask why a field burns or a plague spreads, don''''t ask why I fight.
---------------Battle doesn't need a purpose, the battle is its own purpose. You don't ask why a field burns or a plague spreads, don''t ask why I fight.
To output binary instead of text:
|
you can use stream objects. That way, you can output ints, chars, everything (that is defined)
Check out my raytracer at http://simp-raytracer.sourceforge.net. Download it at http://www.sourceforge.net/projects/simp-raytracer.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement