我正在学习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