के सेट के साथ काम ढूंढना मैं कई स्ट्रिंग वाले structs को पकड़ने के लिए एक सेट का उपयोग कर रहा हूं। मैं सेट की खोज() कार्यक्षमता का उपयोग करने में सक्षम होना चाहता हूं। हालांकि, चूंकि सेट स्ट्रक्चर धारण कर रहा है, यह काम नहीं करता है। मैं खोजने के लिए स्ट्रक्चर में तारों में से एक को देखने के लिए() ढूंढना चाहता हूं। यह कैसे किया जा सकता है?structs
यहां वह कोड है जिसे मैंने उपयोग करने का प्रयास किया था। यह उस भाग को छोड़कर ठीक काम करता है जहां() का उपयोग किया जाता है।
test.cpp:30:7: error: no matching member function for call to 'find'
s.find("key");
~~^~~~
In file included from test.cpp:3:
In file included from /usr/include/c++/4.2.1/set:65:
/usr/include/c++/4.2.1/bits/stl_set.h:429:7: note: candidate function not viable: no known conversion from 'const char [4]' to 'const key_type' (aka 'const test') for 1st argument
find(const key_type& __x)
^
/usr/include/c++/4.2.1/bits/stl_set.h:433:7: note: candidate function not viable: no known conversion from 'const char [4]' to 'const key_type' (aka 'const test') for 1st argument
find(const key_type& __x) const
^
1 error generated.
ऐसा करने के लिए कोड क्या है? मैं <ऑपरेटर को अधिभारित कर सकता हूं लेकिन वही विधि == के लिए काम नहीं करती है। –
@ z-buffer: मेरे उत्तर का अद्यतन संस्करण देखें। आपकी समस्या यह है कि आपको अपनी 'test' संरचना के उदाहरण के साथ 'find()' प्रदान करना होगा। – beduin