CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2009
    Posts
    5

    Exclamation newb @ c++, need help

    Hey Guys,

    I'm pretty new to c++ programming and what i want to do is make an int into a string (i.e. int 85 into like '8','5'). I've looked around and many people have used spintf, but how would i make it convert the 85 into a string. Cause after i convert it into a string i need to multiply it. (e.g. 8x5 = 40)

    Any help would be appriciated.

    Cheers

  2. #2
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    894

    Re: newb @ c++, need help

    Well then, you first multiply and then convert it to a string:
    Code:
    int v1 = 8;
    int v2 = 5;
    int v3 = v1 * v2;
    
    TCHAR buffer[64];
    _stprintf(buffer, _T("%d"), v3);

  3. #3
    Join Date
    Aug 2009
    Posts
    5

    Re: newb @ c++, need help

    It's not separate ints, first it is a whole number (i.e. 85) and i need to separate the whole number into 8 and 5.

    Cheers

  4. #4
    Join Date
    Aug 2008
    Location
    Scotland
    Posts
    379

    Re: newb @ c++, need help

    Hope this isn't homework. Do you mean something like:

    Code:
    int myNum = 85;
    int digit;
    int product = 1;
    while (myNum > 0)
    {
        digit = myNum % 10;
        product = product * digit;
        myNum = myNum / 10;
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured