【发布时间】:2018-10-26 14:16:02
【问题描述】:
我是 C++ 新手,因此在完成某项任务时需要一些帮助。问题是,我必须同时迭代三个或更多向量,如下所示:
#include <vector>
#include <iostream>
#include <string>
#include <boost/range/combine.hpp>
using namespace std;
int main(int, char**) {
vector<string> questions = {"Planet", "Rocket", "Galaxy"};
vector<string> answers = {"Planet", "Saturn", "Star"};
vector<int> count = { 12, 34, 79};
vector<int> score = { 324, 956, 289};
vector<int> result;
vector<int> subscore;
string a, q;
int c, s;
for ( const string q : questions ) {
int match = 0;
for( auto tuple : boost::combine(answers, count) ) {
boost::tie(a,c) = tuple;
if( q.substr(0,2) == a.substr(0,2)) {std::cout << q.substr(0,3) << " " << a.substr(0,3) << endl; match = c; }
else cout << "No match!" << '\n';
}
if( match ) { result.push_back(match); }
else result.push_back(0); subscore.push_back(0);
这种方法有效,但我不能在我们正在使用的框架中使用它。
也许这里有人可以向我指出一个类似的解决方案,它不依赖于 boost 但仍然有效。
非常感谢!
【问题讨论】:
-
为什么不能在你的框架中使用 boost?
-
用老好的索引还不够花哨?
-
使用 ROOT 数据分析框架。默认情况下它不知道提升。因此,使用标准 C++ 可能是一种更好的方法
-
一个框架不会把你限制在它“知道”的东西上,或者它不是一个框架或更多的障碍。