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. Converting a Text into an Integer

Converting a Text into an Integer

Scheduled Pinned Locked Moved C / C++ / MFC
question
2 Posts 2 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.
  • R Offline
    R Offline
    Rane
    wrote on last edited by
    #1

    Hi, I'm in need of a conversion routine to convert a string into a integer(long). I'm relying on CRT function _tcstol to do this. Below shown is my approach: main() { _TCHAR *q = 0; char txt[] = "5x"; long l = _tcstol(txt, &q, 10); if (q && _tcsclen(q)) { cout<<"Invalid Integer"; } } I'm relying on parameter2 in _tcstol to validate a integer. (i.e)the endptr Pointer to character that stops scan. Will this approach work fine in all cases? Thanks in Advance :rose: Rane

    stefanmihaimogaS 1 Reply Last reply
    0
    • R Rane

      Hi, I'm in need of a conversion routine to convert a string into a integer(long). I'm relying on CRT function _tcstol to do this. Below shown is my approach: main() { _TCHAR *q = 0; char txt[] = "5x"; long l = _tcstol(txt, &q, 10); if (q && _tcsclen(q)) { cout<<"Invalid Integer"; } } I'm relying on parameter2 in _tcstol to validate a integer. (i.e)the endptr Pointer to character that stops scan. Will this approach work fine in all cases? Thanks in Advance :rose: Rane

      stefanmihaimogaS Offline
      stefanmihaimogaS Offline
      stefanmihaimoga
      wrote on last edited by
      #2

      Hello, yes, I would do the same as you did for converting a string to an integer. By the way, have you looked at this thread[^]? Best regards, Mihai Moga

      Computer Software Professional

      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