我正在學習C++在Stanley Lippman的書上。我正在研究名爲「class Bitset」的段落。有一個練習,他給我的數字序列轉換成bitset < 32>。bitset和數字序列C++
數值序列爲:1,2,3,5,8,13,21。我可以問你,我的代碼是否適合這種數字序列? Lippman還希望我使用bitset中的每一位來表示序列,但bitset是否可以存儲多於一個值?林做第一次和我得到的唯一的想法是:
int index = 0;
const int size_ = 7;
unsigned long f2[size_];
int main()
{
setlocale(LC_ALL,"rus");
string try1;
cout << "Type your numerical sequence in binary code: " << endl;
while (cin >> try1) {
bitset<32> go(try1);
if (go.to_ulong() > 21) { cout << "End of sequence" << endl; break; }
f2[index] = go.to_ulong();
index++;
try1.clear();
go.reset();
}
for (index; index >= 0; index--) {
cout << f2[index] << " ";
}
system("pause");
return 0;
}
你不是應該設置位1,2,3,5,8,13和21嗎? – molbdnilo
給出序列:1,2,3,5,8,13,21。我如何初始化 的對象位集<32>來表示它?如何分配值以將 這個序列表示爲空位矢量?寫入初始化選項 ,併爲每個位分配一個值的變體 – FishTheBig
在這裏,我真的不明白他要求我做什麼 – FishTheBig