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. Simple but I forgot...

Simple but I forgot...

Scheduled Pinned Locked Moved C / C++ / MFC
c++javascriptquestion
6 Posts 5 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.
  • B Offline
    B Offline
    blink4me
    wrote on last edited by
    #1

    BODY, P, TD { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10pt } H2,H3,H4,H5 { color: #ff9900; font-weight: bold; } H2 { font-size: 13pt; } H3 { font-size: 12pt; } H4 { font-size: 10pt; color: black; } PRE { BACKGROUND-COLOR: #FBEDBB; FONT-FAMILY: "Courier New", Courier, mono; WHITE-SPACE: pre; } CODE { COLOR: #990000; FONT-FAMILY: "Courier New", Courier, mono; }

    I am fairly new to Visual C++ Programming but I have experience in C. I want to display the content of a string in a string. Printf("Welcome %s.", name);, in C, I did it like this but in Visual C++, I have a string m_strWelcome and I want to display m_strName in it like above. How? // JS Paquet cout << "Thank you all" << endl;

    S J D B 4 Replies Last reply
    0
    • B blink4me

      BODY, P, TD { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10pt } H2,H3,H4,H5 { color: #ff9900; font-weight: bold; } H2 { font-size: 13pt; } H3 { font-size: 12pt; } H4 { font-size: 10pt; color: black; } PRE { BACKGROUND-COLOR: #FBEDBB; FONT-FAMILY: "Courier New", Courier, mono; WHITE-SPACE: pre; } CODE { COLOR: #990000; FONT-FAMILY: "Courier New", Courier, mono; }

      I am fairly new to Visual C++ Programming but I have experience in C. I want to display the content of a string in a string. Printf("Welcome %s.", name);, in C, I did it like this but in Visual C++, I have a string m_strWelcome and I want to display m_strName in it like above. How? // JS Paquet cout << "Thank you all" << endl;

      S Offline
      S Offline
      Shog9 0
      wrote on last edited by
      #2

      CString has this nice method called Format() that works just like sprintf():

      CString strName = "Josh";
      CString strWelcome;
      strWelcome.Format("Welcome %s.", strName);

      Or you could do:

      CString strName = "Josh";
      CString strWelcome = "Welcome " + strName + '.';

      Your preference :) farewell goodnight last one out turn out the lights

      Smashing Pumpkins, Tales of a Scorched Earth

      B 1 Reply Last reply
      0
      • B blink4me

        BODY, P, TD { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10pt } H2,H3,H4,H5 { color: #ff9900; font-weight: bold; } H2 { font-size: 13pt; } H3 { font-size: 12pt; } H4 { font-size: 10pt; color: black; } PRE { BACKGROUND-COLOR: #FBEDBB; FONT-FAMILY: "Courier New", Courier, mono; WHITE-SPACE: pre; } CODE { COLOR: #990000; FONT-FAMILY: "Courier New", Courier, mono; }

        I am fairly new to Visual C++ Programming but I have experience in C. I want to display the content of a string in a string. Printf("Welcome %s.", name);, in C, I did it like this but in Visual C++, I have a string m_strWelcome and I want to display m_strName in it like above. How? // JS Paquet cout << "Thank you all" << endl;

        J Offline
        J Offline
        Justin Neville
        wrote on last edited by
        #3

        If you're using a string class like the STL string or MFC CString you can use the overloaded operators to concatenate two strings, i.e. m_strWelcome = _T("Welcome ") + m_strName. The MFC CString class does provide a Format() function which works similar to printf() to format a string. Justin Neville

        1 Reply Last reply
        0
        • B blink4me

          BODY, P, TD { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10pt } H2,H3,H4,H5 { color: #ff9900; font-weight: bold; } H2 { font-size: 13pt; } H3 { font-size: 12pt; } H4 { font-size: 10pt; color: black; } PRE { BACKGROUND-COLOR: #FBEDBB; FONT-FAMILY: "Courier New", Courier, mono; WHITE-SPACE: pre; } CODE { COLOR: #990000; FONT-FAMILY: "Courier New", Courier, mono; }

          I am fairly new to Visual C++ Programming but I have experience in C. I want to display the content of a string in a string. Printf("Welcome %s.", name);, in C, I did it like this but in Visual C++, I have a string m_strWelcome and I want to display m_strName in it like above. How? // JS Paquet cout << "Thank you all" << endl;

          D Offline
          D Offline
          dazinith
          wrote on last edited by
          #4

          i dunno if this is the best way since im a newbie too.. but heres how i've been doing it so far CString strTemp; CString strName("dzgraphics.com"); strTemp.Format("I really like %s",strName); AfxMessageBox(strTemp); -dz

          1 Reply Last reply
          0
          • S Shog9 0

            CString has this nice method called Format() that works just like sprintf():

            CString strName = "Josh";
            CString strWelcome;
            strWelcome.Format("Welcome %s.", strName);

            Or you could do:

            CString strName = "Josh";
            CString strWelcome = "Welcome " + strName + '.';

            Your preference :) farewell goodnight last one out turn out the lights

            Smashing Pumpkins, Tales of a Scorched Earth

            B Offline
            B Offline
            blink4me
            wrote on last edited by
            #5

            Thanks all, but the one that I used and that seemed to work well was: CString strName = "Josh"; CString strWelcome = "Welcome " + strName + '.'; // JS Paquet cout << "Thank you all" << endl;

            1 Reply Last reply
            0
            • B blink4me

              BODY, P, TD { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10pt } H2,H3,H4,H5 { color: #ff9900; font-weight: bold; } H2 { font-size: 13pt; } H3 { font-size: 12pt; } H4 { font-size: 10pt; color: black; } PRE { BACKGROUND-COLOR: #FBEDBB; FONT-FAMILY: "Courier New", Courier, mono; WHITE-SPACE: pre; } CODE { COLOR: #990000; FONT-FAMILY: "Courier New", Courier, mono; }

              I am fairly new to Visual C++ Programming but I have experience in C. I want to display the content of a string in a string. Printf("Welcome %s.", name);, in C, I did it like this but in Visual C++, I have a string m_strWelcome and I want to display m_strName in it like above. How? // JS Paquet cout << "Thank you all" << endl;

              B Offline
              B Offline
              Bill Wilson
              wrote on last edited by
              #6

              I'm not suer if the other posts answered your question. They discuss formatting, but not printing. Assuming m_strWelcome is a CString... Printf("Welcome %s.", LPCSTR(m_strWelcome));, Good luck., Bill

              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