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. CString("hai").Format("hello");

CString("hai").Format("hello");

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
9 Posts 7 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.
  • X Offline
    X Offline
    xcavin
    wrote on last edited by
    #1

    AfxMessageBox(CString("hai")); //works fine AfxMessageBox(CString("hai").Format("hello")); //gives error, any way to make this work without having a CString variable?.

    P O R 3 Replies Last reply
    0
    • X xcavin

      AfxMessageBox(CString("hai")); //works fine AfxMessageBox(CString("hai").Format("hello")); //gives error, any way to make this work without having a CString variable?.

      P Offline
      P Offline
      pc_dev
      wrote on last edited by
      #2

      :wtf:

      1 Reply Last reply
      0
      • X xcavin

        AfxMessageBox(CString("hai")); //works fine AfxMessageBox(CString("hai").Format("hello")); //gives error, any way to make this work without having a CString variable?.

        O Offline
        O Offline
        One Stone
        wrote on last edited by
        #3

        :wtf:

        1 Reply Last reply
        0
        • X xcavin

          AfxMessageBox(CString("hai")); //works fine AfxMessageBox(CString("hai").Format("hello")); //gives error, any way to make this work without having a CString variable?.

          R Offline
          R Offline
          RChin
          wrote on last edited by
          #4

          I'm not quite clear on what you want to achieve. In any case, you cannot use the CString constructor like that in the second case.


          I Dream of Absolute Zero

          2 1 Reply Last reply
          0
          • R RChin

            I'm not quite clear on what you want to achieve. In any case, you cannot use the CString constructor like that in the second case.


            I Dream of Absolute Zero

            2 Offline
            2 Offline
            224917
            wrote on last edited by
            #5

            RChin wrote: In any case, you cannot use the CString constructor like that in the second case. I feel its a valid call. But gives an error coz CString::Format() returns void.


            suhredayan
            There is no spoon.

            R 1 Reply Last reply
            0
            • 2 224917

              RChin wrote: In any case, you cannot use the CString constructor like that in the second case. I feel its a valid call. But gives an error coz CString::Format() returns void.


              suhredayan
              There is no spoon.

              R Offline
              R Offline
              RChin
              wrote on last edited by
              #6

              suhredayan® wrote: I feel its a valid call. But gives an error coz CString::Format() returns void. You're absolutely correct. My bad :doh:. The following does indeed compile, though how it could be used in a useful way is still a puzzle. (since it cannot be assigned to anything) :|

              void MyFunction()
              {
               CString("Hey").Format("There!");
              }
              

              I Dream of Absolute Zero

              B A 2 Replies Last reply
              0
              • R RChin

                suhredayan® wrote: I feel its a valid call. But gives an error coz CString::Format() returns void. You're absolutely correct. My bad :doh:. The following does indeed compile, though how it could be used in a useful way is still a puzzle. (since it cannot be assigned to anything) :|

                void MyFunction()
                {
                 CString("Hey").Format("There!");
                }
                

                I Dream of Absolute Zero

                B Offline
                B Offline
                Bob Ciora
                wrote on last edited by
                #7

                That compiles *and* runs successfully. The problem is that CString::Format's return type is void. So that's the return type of this statement, and there doesn't seem to be any way to convert that to the LPCTSTR that AfxMessageBox expects. It's going to take some serious obfuscation to make this work. My question is...what's wrong with a local CString variable? Like it or not, the statement itself is creating a local CString that goes out of scope after the statement executes. Bob Ciora

                2 1 Reply Last reply
                0
                • R RChin

                  suhredayan® wrote: I feel its a valid call. But gives an error coz CString::Format() returns void. You're absolutely correct. My bad :doh:. The following does indeed compile, though how it could be used in a useful way is still a puzzle. (since it cannot be assigned to anything) :|

                  void MyFunction()
                  {
                   CString("Hey").Format("There!");
                  }
                  

                  I Dream of Absolute Zero

                  A Offline
                  A Offline
                  Antti Keskinen
                  wrote on last edited by
                  #8

                  Although this is a valid call, isn't it a bit like asking for "unpredictable results" to come your way ?

                  CString strText( _T("Hey") );
                  strText += _T(" there !");

                  Much easier, much simpler, and compiles correctly :D -Antti Keskinen ---------------------------------------------- "If we wrote a report stating we saw a jet fighter with a howitzer, who's going to believe us ?" -- R.A.F. pilot quote on seeing a Me 262 armed with a 50mm Mauser cannon.

                  1 Reply Last reply
                  0
                  • B Bob Ciora

                    That compiles *and* runs successfully. The problem is that CString::Format's return type is void. So that's the return type of this statement, and there doesn't seem to be any way to convert that to the LPCTSTR that AfxMessageBox expects. It's going to take some serious obfuscation to make this work. My question is...what's wrong with a local CString variable? Like it or not, the statement itself is creating a local CString that goes out of scope after the statement executes. Bob Ciora

                    2 Offline
                    2 Offline
                    224917
                    wrote on last edited by
                    #9

                    Bob Ciora wrote: It's going to take some serious obfuscation to make this work. My question is...what's wrong with a local CString variable? Like it or not, the statement itself is creating a local CString that goes out of scope after the statement executes. Its all about trying to show the geekness, wot you feel cing the following. int fun(tchar* buff,tchar* szFnd,int n) { .... .... return CString(buff).Right(n).Find(szFnd); } ;)


                    suhredayan
                    There is no spoon.

                    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