C++ 举例说明在C+中作为结构成员的位集+;
我不知道如何使用位集作为结构的成员。当我得到这个C++ 举例说明在C+中作为结构成员的位集+;,c++,C++,我不知道如何使用位集作为结构的成员。当我得到这个 > [错误]:ISO C++禁止声明“BySt集”,没有类型< /强> 代码: typedef结构 { 位集状态;//按位状态 }地位; 在堆栈溢出时,提供更多的示例说明您尝试了什么,以及您在哪里寻求帮助,这通常被认为是有礼貌的。例如,您可能会说您试图理解 但这里有: #include <iostream> #include <bitset> // you'll need to include this struc
<强> > [错误]:ISO C++禁止声明“BySt集”,没有类型< /强> 代码:
typedef结构
{
位集状态;//按位状态
}地位;
在堆栈溢出时,提供更多的示例说明您尝试了什么,以及您在哪里寻求帮助,这通常被认为是有礼貌的。例如,您可能会说您试图理解
但这里有:
#include <iostream>
#include <bitset> // you'll need to include this
struct status_t {
std::bitset<11> status; // note the std - it's in that namespace
};
int main()
{
status_t stat;
for (auto i = 0; i < 11 ; i += 2)
stat.status.set(i);
std::cout << "values: " << stat.status << "!\n";
}
#包括
#include//您需要将此
结构状态{
std::bitset status;//注意std-它在该名称空间中
};
int main()
{
状态统计;
对于(自动i=0;i<11;i+=2)
统计状态集(i);
std::cout这种错误可能是由于忽略了位集include,或者没有指定std名称空间造成的
要纠正这个问题:
1) 确保包含位集:
#include <bitset>
或者在位集声明前加上std:
std::bitset<10> status; //bitwise status
std::位集状态;//按位状态
因此,您的最终文件片段可能如下所示:
#include <bitset>
// other code ...
typedef struct {
std::bitset<10> status; // bitwise status
}Status;
// the rest of the file ...
#包括
//其他代码。。。
类型定义结构{
std::位集状态;//按位状态
}地位;
//文件的其余部分。。。
这是std::bitset
。别忘了#include
我已经这么做了。但它仍然会产生这个错误。卡尔,如果我有50个声誉,我会在你的问题中添加这个评论,而不是我的答案,但是我没有……你能提供关于这个问题的更多细节吗?也许是一个完整的源文件,操作系统你正在运行,你正在使用的编译器是什么?
std::bitset<10> status; //bitwise status
#include <bitset>
// other code ...
typedef struct {
std::bitset<10> status; // bitwise status
}Status;
// the rest of the file ...