Saturday, May 22, 2010

C++ question?

I am trying to make "cin" accept multiple "digits" under an assigned variable char. Is there any other way to do this other than assigning char to a character string?

C++ question?
You are trying to cin multiple digits to one char variable? It has been a while since I have used C++, but a type char variable is 1 byte and a digit character is 1 byte, therefore to store multiple digit characters in a char is impossible due to the size.





Now if you take the numerical representaiton of the digits and it is less then 255 then you could store that in a char. So if you entered 99 you could take the character representation of that digit and use that. Then when you want the digits back, you could take the character and find the numerical representation. Sorry if that is confusing.
Reply:heres how you do it:


char digits[81] ;


cout%26lt;%26lt;"Please enter digits"%26lt;%26lt;endl;


cin.get(digits,80) ;





by the way i spaced out the semicolons just in case if you were wondering.
Reply:char [20] varName;


No comments:

Post a Comment