Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7716711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:42:05+00:00 2026-06-01T02:42:05+00:00

How can i create a boost::format type formatter object using the character-string or std::string

  • 0

How can i create a boost::format type formatter object using the character-string or std::string.
Trying to use following code which doesn’t run. Want to achieve code equivalent to following code (semantically):

    format fobj("first-> %1% , second-> %2%");
    std::stringstream s;
    s<<fobj %1 %"%1%.";    //so that I can use s.str() to create a boost object
// How to create fmt object  HERE  
    ss<< fmt %"replacedtext";
    cout<<s.str()<<endl;
    cout<<ss.str();

Sample case:
s should be “first-> 1 , second-> %1%.”
so that I can use this s.str() string to create another format object fmt to which i can feed the substitution values.

Any thoughts folks??

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T02:42:06+00:00Added an answer on June 1, 2026 at 2:42 am

    It’s not clear to me what you are trying to do, the boost::format docs are a good place to start, there are a number of clear examples showing how to use the class.

    You can create a formatter object and feed elements in via different operations (unlike say, printf where all params need to satisfy the va_arg you pass in).

    boost::format fmter("%2% %1%");
    fmter % 36; 
    fmter % 77;
    

    You can then obtain a string from the result.

    std::string s  = fmter.str();
    

    Be aware there are a number of exceptions that can be thrown.

    If you are looking for something that dynamically creates a format string you can do that in any number of ways.

    std::string strFormatString = "first-> %1% second-> %2%";
    boost::format formatter( strFormatString.c_str() );
    formatter % value1;
    formatter % strFormatString.c_str();
    boost::format secondFormatter( formatter.str() );  // etc etc etc
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have method: void foo(const std::string& s); Can I create boost::function: boost::function<void(const std::string&)>
I use boost::asio::buffer to send a message using void Send(const std::string& messageData) { socket.async_write(boost::asio::buffer(messageData),
How can I create a const boost matrix? The following did not work: const
Let's say that I have a boost::variant<std::string, int> myVariant; In this object I keep
I'm trying to create an HTTP client using Boost Asio. I copied the sync
I'm using learning the basic of boost.thread. So far, I can create each thread
I'm trying to create a static vector-of-vectors and I'm finding that the following code
I'm using boost::ptree for parsing fils. The problem is that I can't create the
One can create an anonymous object that is initialized through constructor parameters, such as
I can create a sparse php array (or map) using the command: $myarray =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.