Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How we can convert string to number or number to string?

How we can convert string to number or number to string?

Scheduled Pinned Locked Moved C / C++ / MFC
question
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mehdi_Hosseinpour
    wrote on last edited by
    #1

    I want to convert a number like (i=3546246547) to a string variable( str='3546246547') and vice versa. How can we do this? Mehdi Hosseinpour

    Y A T 3 Replies Last reply
    0
    • M Mehdi_Hosseinpour

      I want to convert a number like (i=3546246547) to a string variable( str='3546246547') and vice versa. How can we do this? Mehdi Hosseinpour

      Y Offline
      Y Offline
      YanivNahum
      wrote on last edited by
      #2

      try the atoi and _itoa or use CString: CString str; int i = 3546246547; str.Format("%d",i);

      1 Reply Last reply
      0
      • M Mehdi_Hosseinpour

        I want to convert a number like (i=3546246547) to a string variable( str='3546246547') and vice versa. How can we do this? Mehdi Hosseinpour

        A Offline
        A Offline
        Anonymous
        wrote on last edited by
        #3

        CString is MFC specific. If you're not creating an MFC application and don't want to bloat your code use the following CRT data conversion routines. strtoul, wcstoul - Converts string to unsigned long integer. _ultoa, _ultow - Converts unsigned long to string. For more data conversion functions search MSDN for "Data Conversion Routines"

        1 Reply Last reply
        0
        • M Mehdi_Hosseinpour

          I want to convert a number like (i=3546246547) to a string variable( str='3546246547') and vice versa. How can we do this? Mehdi Hosseinpour

          T Offline
          T Offline
          toxcct
          wrote on last edited by
          #4

          there is also another way to convert values into strings with the sprintf() fonction :

          #include <string.h>
          int sprintf(char* buffer, const char* format, ...);
          //...

          you can use it like printf(), giving it a pointer to where the string will be stored TOXCCT alias Nicolas C.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups