Hello, I have just recently (yesterday) began learning cpp. I have been going over the tutorials offered on this site and I have stumbled across a small problem. I am attempting to create a tester program to see if I am grasping what I have learned so far. My problem occurs when I attempt to discover the length of an integer.
I am aware of the strlen function that will return the length of a string. However I desire to know the length of variable that is an integer.
So far I have tried making a string that variable but the compiler refuses on the grounds that it cannot accept a 'char string' is equal to an 'int variable'. Like so
I understand that it cannot be done this way.Code:... char vse; int vx; ... vse=vx; ...
Then I reread typcasting, in hopes that I could find a way to play with the int/char types and be allowed to convert my int variable into a string and use strlen. Unfortuneatly I cannot figure out a feasible way to use typcasting to solve my problem.
In short, I am looking for a way to know how many digits a number has.
111 --> 3
1111 --> 4
Is there a way to find this?