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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. two q's..._T("What the heck?") and handling CString's as float's

two q's..._T("What the heck?") and handling CString's as float's

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelp
5 Posts 4 Posters 1 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.
  • C Offline
    C Offline
    Cam
    wrote on last edited by
    #1

    I have two questions I could really use some help with...first of all, what is the difference between the two following function calls?: (1): m_cTabListMode.InsertItem(0, _T("Icon")); (2): m_cTabListMode.InsertItem(0, "Icon"); What is the "_T()" thing for...? :confused: Ok, second question. I'm working with a list control, and I need to display prices of particular items in one column of my listctrl. Below my list control I have an editbox which needs to contain the total price of all of the items in the listbox. As the listctrl requires that the prices be CString's, how do I convert them back to float's so that I can add up the total? Help on either topic would be greatly appreciated! -Cam Desautels

    C PJ ArendsP 2 Replies Last reply
    0
    • C Cam

      I have two questions I could really use some help with...first of all, what is the difference between the two following function calls?: (1): m_cTabListMode.InsertItem(0, _T("Icon")); (2): m_cTabListMode.InsertItem(0, "Icon"); What is the "_T()" thing for...? :confused: Ok, second question. I'm working with a list control, and I need to display prices of particular items in one column of my listctrl. Below my list control I have an editbox which needs to contain the total price of all of the items in the listbox. As the listctrl requires that the prices be CString's, how do I convert them back to float's so that I can add up the total? Help on either topic would be greatly appreciated! -Cam Desautels

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Float to CString: mystring.Format("%.2f", myfloat); CString to float myfloat to atof(mystring); I *believe* the _T makes the string Unicode ? It's something *like* that, and is certainly superfluous in my experience ( i.e. I've never needed to do it or broken anything by not doing it ) Christian The content of this post is not necessarily the opinion of my yadda yadda yadda. To understand recursion, we must first understand recursion.

      C 1 Reply Last reply
      0
      • C Cam

        I have two questions I could really use some help with...first of all, what is the difference between the two following function calls?: (1): m_cTabListMode.InsertItem(0, _T("Icon")); (2): m_cTabListMode.InsertItem(0, "Icon"); What is the "_T()" thing for...? :confused: Ok, second question. I'm working with a list control, and I need to display prices of particular items in one column of my listctrl. Below my list control I have an editbox which needs to contain the total price of all of the items in the listbox. As the listctrl requires that the prices be CString's, how do I convert them back to float's so that I can add up the total? Help on either topic would be greatly appreciated! -Cam Desautels

        PJ ArendsP Offline
        PJ ArendsP Offline
        PJ Arends
        wrote on last edited by
        #3

        _T(x) is a macro that that makes a string literal Unicode compliant. from TChar.h #define _T(x) __T(x) #define _TEXT(x) __T(x) and elsewhere in TChar.h #ifdef _UNICODE ... #define __T(x) L ## x ... #else ... #define __T(x) x ... #endif so _T("Icon") becomes "Icon" if _UNICODE is not defined, and L"Icon" if _UNICODE is defined So if you are not writing a Unicode app, there is no difference between the two function calls, but if you are using Unicode, there is a definite difference.

        Within you lies the power for good; Use it!

        L 1 Reply Last reply
        0
        • C Christian Graus

          Float to CString: mystring.Format("%.2f", myfloat); CString to float myfloat to atof(mystring); I *believe* the _T makes the string Unicode ? It's something *like* that, and is certainly superfluous in my experience ( i.e. I've never needed to do it or broken anything by not doing it ) Christian The content of this post is not necessarily the opinion of my yadda yadda yadda. To understand recursion, we must first understand recursion.

          C Offline
          C Offline
          Cam
          wrote on last edited by
          #4

          Thank you, very, very much.

          1 Reply Last reply
          0
          • PJ ArendsP PJ Arends

            _T(x) is a macro that that makes a string literal Unicode compliant. from TChar.h #define _T(x) __T(x) #define _TEXT(x) __T(x) and elsewhere in TChar.h #ifdef _UNICODE ... #define __T(x) L ## x ... #else ... #define __T(x) x ... #endif so _T("Icon") becomes "Icon" if _UNICODE is not defined, and L"Icon" if _UNICODE is defined So if you are not writing a Unicode app, there is no difference between the two function calls, but if you are using Unicode, there is a definite difference.

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            Another difference. If you are writing a UNICODE application, it runs on NT/2000/XP only. If you are writing an MBCS/SBCS application, it runs on all the operating systems, and when run on NT/2000/XP the MBCS/SBCS application will run slower than the UNICODE application because all MBCS/SBCS strings are converted to UNICODE strings at the Win32 API boundary. Matt Pietrek wrote an article on this years ago. So, Christian, for your Win NT/2000 applications, maybe you should make a UNICODE build? Slight Aside: If you are doing many multilanguage apps, there are so MBCS only bugs out there which will bring the box to its knees (the debugger doesn't even get a chance). Stephen Kellett

            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