因为工作需要,需要频繁用的字符串拼接,参数还不固定,所以写了下面的例子,算是给自己的记录

#include "stdafx.h"
#include <iostream>
#include <string>
#include <sstream> 

using namespace std;

template<class T>

void addString(string& strItem, T arg)
{
	std::ostringstream oss;
	std::string strValue = "";
	oss << arg;
	strValue = oss.str();
	strItem += strValue;
}

template<class... Args>
std::string stringOutput(Args... args) 
{
	std::string strRet;
	int arr[] = { (addString(strRet, args), 0)... };
	return strRet;
}
int main()
{
	string str = "qwe";
	char buf[12] = { 0 };
	memcpy(buf, str.c_str(), str.length());
	std::cout << stringOutput("你好~~~", 1234, "OKk", 1.23546, buf, str);

    return 0;
}

  

 

相关文章:

  • 2022-12-23
  • 2021-06-09
  • 2022-12-23
  • 2021-06-22
  • 2022-12-23
  • 2022-12-23
  • 2021-12-17
  • 2022-01-25
猜你喜欢
  • 2022-12-23
  • 2022-01-08
  • 2021-06-13
  • 2022-12-23
  • 2023-02-02
  • 2022-12-23
相关资源
相似解决方案