Either approach is valid whether it be via stringstream or via sprintf. Since this is a C++ forum then naturally we would recommend the stringstream approach. However that does not make it more or less right in a purely technical sense. Both will accomplish the goal and both will get the job done. To me there is no benefit in using C++ just to be more C++-ey and in this instance it makes no difference either way. When I use a C++ approach to solve a problem it is for a very distinct reason and to serve a specific purpose. It is not merely to please the C++ gods whoever they may be or to look myself in the mirror in the morning and pride myself on being a C++ programmer.
Either approach is valid whether it be via stringstream or via sprintf. Since this is a C++ forum then naturally we would recommend the stringstream approach. However that does not make it more or less right in a purely technical sense. Both will accomplish the goal and both will get the job done. To me there is no benefit in using C++ just to be more C++-ey and in this instance it makes no difference either way. When I use a C++ approach to solve a problem it is for a very distinct reason and to serve a specific purpose. It is not merely to please the C++ gods whoever they may be or to look myself in the mirror in the morning and pride myself on being a C++ programmer.
This I know. But there can also be a bad reason behind using the C approach.
So I want to make sure. Why is a C++ dev using C to get the job done? It's error prone and vulnerable to buffer overruns.
If it's a valid reason, then code away.
Originally Posted by Adak
io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
Originally Posted by Salem
You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.
Outside of your DOS world, your header file is meaningless.