我快我的代码,除了我需要两个东西帮助下完成的数组。这是我的代码:Code。对于下面的函数,我试图让我可以使用“n”的输入来初始化我的数组myBits,而不是一个常数,它现在是5.初始化具有可变大小的
我的其他问题就在下面。我试图将所有最右边的位切换到“真”。我在“/ * ..... * /”中编写了for循环,但似乎没有工作。正上方,我做长的方式为C(5,4)...(myBit [0] = myBit [1] ....等......(我使用此找到R-字符串的组合)....和它似乎工作。任何帮助,将不胜感激!!
void nCombination(const vector<string> &Vect, int n, int r){
bool myBits[5] = { false }; // everything is false now
myBits[1] = myBits[2] = myBits[3] = myBits[4] = true;
/* for(int b = n - r - 1; b = n - 1; b++){
myBits[b] = true; // I am trying to set the r rightmost bits to true
}
*/
do // start combination generator
{
printVector(Vect, myBits, n);
} while (next_permutation(myBits, myBits + n)); // change the bit pattern
}
使用'的std ::矢量 myBits(正,假)'返回。 –
PaulMcKenzie
2014-12-04 21:49:09
注意,[可变长度数组是没有的部分标准C++](http://stackoverflow.com/q/21273829/1708801)的替代方法是使用[标准::矢量](http://en.cppreference.com/w/cpp/container/vector)或[std :: array](http://en.cppreference.com/w/cpp/container/array)。 – 2014-12-04 21:49:20
为了将r个最右边的位设置为true,我的循环出了什么问题? – 2014-12-04 22:03:01