Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 我们可以使用boost格式进行无序排序吗_C++_Boost - Fatal编程技术网

C++ 我们可以使用boost格式进行无序排序吗

C++ 我们可以使用boost格式进行无序排序吗,c++,boost,C++,Boost,让我们直接转到代码 #include <boost/format.hpp> #include <iostream> #include <vector> using namespace std; string strtemplate="First:%1%, Second:%2%"; int main() { vector<string> v; v.push_back("first"); v.push_back("secon

让我们直接转到代码

#include <boost/format.hpp>
#include <iostream>
#include <vector>

using namespace std;

string strtemplate="First:%1%, Second:%2%";
int main()
{
    vector<string> v;
    v.push_back("first");
    v.push_back("second");
#if 0
    cout<<str(boost::format(strtemplate) % v[1] % v[0])<<endl;
#else
    boost::format fmter(strtemplate);
    for(int i=0;i<2;++i)
    {
            fmter % v[i];
    }
    cout<<str(fmter)<<endl;
#endif
    return 0;
}
#包括
#包括
#包括
使用名称空间std;
字符串strtemplate=“第一个:%1%,第二个:%2%”;
int main()
{
向量v;
v、 向后推(“第一”);
v、 推回(“第二”);
#如果0

cout例如,如果向量的顺序相反,为什么不使用如下格式模板

"First: %3%, Second %2%, Third: %1%.";
不过,如果您是这样要求的,那么您需要事先知道输入向量相对于字符串中插槽顺序的顺序。否则,您需要对输入向量进行一些分析,并在运行时构建格式字符串,这有点不符合目的

我强烈建议您查看该库中的字符串格式,它比Boost格式轻量级多,速度也快得多。将其纳入标准的工作正在进行中