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. Is there an equivalent to CString Format in std::string ?

Is there an equivalent to CString Format in std::string ?

Scheduled Pinned Locked Moved C / C++ / MFC
question
5 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.
  • U Offline
    U Offline
    uusheikh
    wrote on last edited by
    #1

    CString has Format method, how can i achieve the same if i'm using std::string?

    S J 2 Replies Last reply
    0
    • U uusheikh

      CString has Format method, how can i achieve the same if i'm using std::string?

      S Offline
      S Offline
      Stephen Hewitt
      wrote on last edited by
      #2

      You have a number of choices. Two spring immediately to mind: 1. Use ostringstream. 2. Use Boost's[^] Format[^] library. Example using the first:

      #include <string>
      #include <sstream>
      #include <iostream>
       
      int main(int argc, char* argv[])
      {
      using namespace std;
       
      ostringstream oss;
      const int one = 1;
      const int two = 2;
      oss << one << " + " << two << " is " << one+two;
       
      cout << oss.str() << endl;
       
      return 0;
      }

      Examples of the second can be found at the link provided. I'd go for the second approach.

      Steve

      U 1 Reply Last reply
      0
      • U uusheikh

        CString has Format method, how can i achieve the same if i'm using std::string?

        J Offline
        J Offline
        Javed Akhtar Ansari
        wrote on last edited by
        #3

        One way is convert std::string to CString using marshalling

        T 1 Reply Last reply
        0
        • S Stephen Hewitt

          You have a number of choices. Two spring immediately to mind: 1. Use ostringstream. 2. Use Boost's[^] Format[^] library. Example using the first:

          #include <string>
          #include <sstream>
          #include <iostream>
           
          int main(int argc, char* argv[])
          {
          using namespace std;
           
          ostringstream oss;
          const int one = 1;
          const int two = 2;
          oss << one << " + " << two << " is " << one+two;
           
          cout << oss.str() << endl;
           
          return 0;
          }

          Examples of the second can be found at the link provided. I'd go for the second approach.

          Steve

          U Offline
          U Offline
          uusheikh
          wrote on last edited by
          #4

          Thanks man! I'll try both methods!

          1 Reply Last reply
          0
          • J Javed Akhtar Ansari

            One way is convert std::string to CString using marshalling

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

            crap


            [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

            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