Think I have an integer array like this:
a[0]=60; a[1]=321; a[2]=5;
now I want to convert the whole of this array into an integer number, for example int b become 603215 after running the code.
How to do it?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Use a
std::stringstream:Note that in C++11 that mildly ugly loop can be replaced with this:
Also, seeing as how there is a good possibility of overflow, the string form of the number can be accessed with
ss.str(). To get around overflow, it might be easier working with that than trying to cram it into an integer. Negative values should be taken into consideration, too, as this will only work (and make sense) if the first value is negative.