में एनम क्लास के मान को कैसे आउटपुट कर सकता हूं I C++ 11 में enum class
के मान को कैसे आउटपुट कर सकता हूं? सी ++ 03 में यह इस तरह है:मैं सी ++ 11
#include <iostream>
using namespace std;
enum A {
a = 1,
b = 69,
c= 666
};
int main() {
A a = A::c;
cout << a << endl;
}
ग में ++ 0x इस कोड संकलन नहीं है
#include <iostream>
using namespace std;
enum class A {
a = 1,
b = 69,
c= 666
};
int main() {
A a = A::c;
cout << a << endl;
}
prog.cpp:13:11: error: cannot bind 'std::ostream' lvalue to 'std::basic_ostream<char>&&'
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/ostream:579:5: error: initializing argument 1 of 'std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&&, const _Tp&) [with _CharT = char, _Traits = std::char_traits<char>, _Tp = A]'
एक unscoped गणन के विपरीत Ideone.com
आप एनम आउटपुट करने का प्रयास क्यों कर रहे हैं? enum क्लास का उपयोग int प्रतिनिधित्व के साथ enum मानों को मिश्रण नहीं करने के लिए किया जाता है – RiaD