i have just started learning c++ programming for my project. my knowledge to c++ is nearly 0%. Please, i hope someone will give me some pointers on the following question.

i am using c++ to control a keypad. i have the code for my keypad to work well. that is whenever a key (1, 2, 3, 4, 5, 6, 7, 8, 9, 0) is pressed, the digit pressed will display on the lcd screen. my problem now is that, i need to store 16 digits pressed into a variable perharps...

for example, i pressed "2" "5" "6" "8" "1" "4".... my variable will store "256814..." which are the digits i pressed.

can some kind souls please give me some pointers on how to store the digits pressed into some location..

12-04-2005

7stud

How are you getting the pressed keys? What type of variable are they stored in?

12-04-2005

Enahs

So you are saying when you type in 123456 you are getting a number corresponding to 123,456 but you want a 1, a 2, a 3, a 4, a 5 and a 6?

12-04-2005

lovemagix

i have a keypad... and my code is continously scanning which buttons is pressed. whenever a button is pressed if will write into the lcd.

...
...
...
for every key pressed, it return the value and put into a int variable, then it is write into the lcd.

i need to use the keypad to input 16 digits... and the 16 digits that are pressed, needed to be record down together..

for example, firstly i pressed "2" then i pressed "5", then "7" and so on, the digits in pressed needed to be store into some place ( required answer : 257............) together

12-04-2005

7stud

You can use what is called a stringstream. It allows you to treat a string like you would a file. For an ouput stringstream, you can write values to the string, just like you would to a file. Then, you can use the str() function to get a string representation of everything written to the string. Here is an example:

thanks a million.... i would like "257" to be an integer... i tried using the search engines to convert string into int... but i do not understand... could you/anyone kindly teach me how to make "257"(in the above example) into interger, please?

help me out with the other 2 problems pretty please... i am really a noob in c++ ..

12-05-2005

Daved

>> Eh? An unsigned long should be 32 bits. An unsigned short would be 16.

Not necessarily... It depends on the platform. This doesn't appear to be a normal Win32 platform, so it is quite possible that a long isn't 32 bits.

12-05-2005

7stud

Quote:

thanks a million.... i would like "257" to be an integer.

Ok. stringstreams can help in that regard too. You can first read the numbers into a ostringstream like in the example code I posted above. Then you can use the str() function to obtain the resulting string, and the resulting string can be used to create an istringstream. An istringstream can be used just like an input file, and you can read data from it into an int variable. Here is the modified code: