Jump to content
  • Advertisement
Sign in to follow this  
jsloan

Basic C++ question

This topic is 5020 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

HI, Is it possible to add a number to an integer without actually 'adding'. Let me show you what i mean
//heres the integer
int number =5;

//heres another one
int number_2 = 1;

//is it possible to do something like
number = number & number_2;

//so instead of number == 6 it would == 51?

Thanks

Share this post


Link to post
Share on other sites
Advertisement
You could do something like number = number * 10 + number_2;, that's definitely the easiest way. It really depends on the context though; it won't work if number_2 is greater than 9.

EDIT: Since you're using C++, a stringstream will do the trick.


std::stringstream ss;

ss << number << number_2;
ss >> number;



Share this post


Link to post
Share on other sites
Quote:
Original post by Ra
You could do something like number = number * 10 + number_2;, that's definitely the easiest way. It really depends on the context though; it won't work if number_2 is greater than 9.


Thats definatly the most creative way. :)

Thanks Guys.

Share this post


Link to post
Share on other sites
Quote:
Original post by mike25025
that will only work for constants
so it would be easyer to type 5336


Yep

But that takes away all the fun

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!