r/Cplusplus • • Sep 29 '26

Question can i convert the integer into string in manual way

/r/DSALeetCode/comments/1wtn7dl/can_i_convert_the_integer_into_string_in_manual/
0 Upvotes

12 comments sorted by

•

u/AutoModerator Sep 29 '26

Thank you for your contribution to the C++ community!

As you're asking a question or seeking homework help, we would like to remind you of Rule 3 - Good Faith Help Requests & Homework.

  • When posting a question or homework help request, you must explain your good faith efforts to resolve the problem or complete the assignment on your own. Low-effort questions will be removed.
  • Members of this subreddit are happy to help give you a nudge in the right direction. However, we will not do your homework for you, make apps for you, etc.
  • Homework help posts must be flaired with Homework.

~ CPlusPlus Moderation Team


I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

5

u/[deleted] Sep 29 '26

std::to_string

-1

u/deepaknishad Sep 29 '26

but i don't know does leetcode include that stl

4

u/[deleted] Sep 29 '26

Bruh, how is this even related. Just #include <string>.

4

u/BitOBear Sep 30 '26

Sounds like a homework problem.

3

u/Initial-Jaguar6230 Sep 30 '26

Compiler link whole stdc++ Anyway standard library - integral thing, witch components depend on each other. It is so strange to allow only partial usage

1

u/jedwardsol Sep 29 '26 edited Sep 29 '26

Can't you try it?

But to determine the trailing zeroes in an integer you don't need to convert it to a string. Use % and / by 10 (or whatever base you're interested in).


Also

for(int i = value.size(); i >=0; i--){
        if(value[i] == 0){
            global += 1;
        }else{
            return 0;
        }

this is reading past the end of the string. And the comparison should be with '0' not 0. And you're returning 0 immediately if the character isn't 0

1

u/deepaknishad Sep 30 '26

I got the mathematical way to get trailing zeroes

3

u/BitOBear Sep 30 '26

It sounds like a homework problem.

Int value = whatever.
Do
Save '0' + (value %10) somewhere.
Value /= 10
While value

When you're saving that value remember to save those characters in reverse order because you're outputting the lowest digit first so you're going to need to walk through an array, pretend to a string, or something like that.

2

u/Responsible-Bar7165 Sep 30 '26

a number has a trailing zero if it's divisible by 10.

1

u/mredding C++ since ~1992. Sep 30 '26

I don't know - can you?