Sign in to follow this  
darklordsatan

On boost, std and c++ standards

Recommended Posts

Hello, A couple of minutes ago I was reading a thread about converting an int to a const char* or something among those lines. Someone replied that the OP should use boost or std to do the conversion, as itoa() wasnt so standard as there were many different signatures for that function. My question is, where (online resources I would be most interested, but books should be ok as a last alternative) can I check if a given function is part of the standard, or is aimed to be really portable. From what I know, std and boost aim to do that, as well as the gcc compiler (which id the main reason I like it), but when I encounter a problem in which I could use many approaches as in the aforementioned thread, how do I know which one is the most standard one, or is this something you can only know by experience and in a per function basis (i.e theres no single resource website or book that can tell me this)? Thanks

Share this post


Link to post
Share on other sites
For the std library, the definitive resource is ISO14882 which is the C++ standard (you also need a copy of the C standard, as it's referenced in the C++ standard).

boost.org has all the info you need about boost.

Another good reference is MSDN. If a function isn't standard, it will usually be surrounded by 'Microsoft specific'/'End Microsoft specific' tags.

Share this post


Link to post
Share on other sites
Converting a char * to int (or vice versa) is nonsensical and you shouldn't do it.

If you mean, converting an int into a C-string using base-10 numbers, then of course that can be done, but it is not a cast of any sort, rather a distinct operation.

Yes, itoa will work. In the past I've used the following template function


using namespace std; // <-- don't do this if you put this in a header

template <typename T> string toString(T obj)
{
ostringstream oss;
oss << obj;
return oss.str();
}


Which will work for any type which has an overload of <<

Mark

Share this post


Link to post
Share on other sites
Quote:
Original post by markr
Converting a char * to int (or vice versa) is nonsensical and you shouldn't do it.

If you mean, converting an int into a C-string using base-10 numbers, then of course that can be done, but it is not a cast of any sort, rather a distinct operation.

Yes, itoa will work. In the past I've used the following template function


using namespace std; // <-- don't do this if you put this in a header

template <typename T> string toString(T obj)
{
ostringstream oss;
oss << obj;
return oss.str();
}


Which will work for any type which has an overload of <<

Mark


Oh no... I was just saying there was a thread in which the OP wanted to do such conversion, and then I asked myself about the c++ standards because of someone's reply to that thread.. hehe

Share this post


Link to post
Share on other sites
Also, the man pages for functions in the gcc world will also tell you if they're part of a standard (C, C++, POSIX, etc.) or an extension.

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