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 9129545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:46:26+00:00 2026-06-17T07:46:26+00:00

code : #include <stdarg.h> #include <string> #include <iostream> std::wstring string_format(const std::wstring &fmt, …) {

  • 0

code :

#include <stdarg.h>
#include <string>
#include <iostream>

std::wstring string_format(const std::wstring &fmt, ...) {
  int size = 100;
  std::wstring str;
  va_list ap;
  while (1) {
    str.resize(size);
    va_start(ap, fmt);
    int n = vsnwprintf((wchar_t *)str.c_str(), size, fmt.c_str(), ap);
    va_end(ap);
    if (n > -1 && n < size) {
      str.resize(n);
      return str;
    }
    if (n > -1) size = n + 1;
    else size *= 2;
    }
  return str;
}

std::wstring printf_wrapper(std::wstring text, ...) {
  using namespace std;
  va_list args;
  va_start(args, text);
  wstring formatted_text = string_format(text, args);
  va_end (args);
  return formatted_text;
}

int main(int argc, char *argv[])
{
    using namespace std;
    wcout << printf_wrapper(L"example%d",1) << endl;
    return 0;
}

and it returns : example2293384

the function is from here: https://stackoverflow.com/a/8098080/393087
origin of this code is from the documentation of vsnprintf: http://www.tin.org/bin/man.cgi?section=3&topic=vsnprintf

  • 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-17T07:46:28+00:00Added an answer on June 17, 2026 at 7:46 am

    You cannot “forward” varargs like that. So string_format needs to take a va_list as its 2nd argument, not ....

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This code: #include <iostream> #include <cstdio> #include <fstream> #include <string> int main() { std::remove(test.txt);
CODE: #include <iostream> #define BUFF 100 using namespace std; int main(int argc, char* argv[])
this code #include <iostream> using namespace std; int main(){ bool t=false; cout<<t &&(!t)<<endl; return
Code #include <iostream> using namespace std; int main() { const int N = 22;
Example code: #include <iostream> int main() { if(int a = std::cin.get() && a ==
Example code: #include <cstdlib> #include <iostream> using namespace std; class A { public: A(int
I have the following code: #include<iostream> using namespace std; typedef void (*HandlerFunc)(int, int); HandlerFunc
Code: #include<iostream> using namespace std; class MyClassOne; class MyClassTwo { int myInteger; float myFloat;
Code: #include <iostream> #include <string> #include <sstream> #include <algorithm> using std::cerr; using std::cout; using
Code: #include<iostream> using namespace std; class B{ public: int b; B(int x):b(x){ cout <<

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.