मैं cout
के माध्यम से अपनी सीमा निर्माता और फिर उन्हें उत्पादन का उपयोग करके एक vector<string
में एक पाठ फ़ाइल से सभी लाइनों लोड करना चाहते हैं:वेक्टर रेंज कन्स्ट्रक्टर का सही तरीके से उपयोग कैसे करें?
#include<iostream>
#include<fstream>
#include<vector>
#include<iterator>
using namespace std;
int main()
{
ifstream file("file.txt");
vector<string> strings(istream_iterator<string>(file) , istream_iterator<string>());
for(auto s : strings)
cout << s << endl;
return 0;
}
जब उदाहरण के लिए, ऊपर दिए गए कोड मैं कई त्रुटियाँ प्राप्त संकलित करने के लिए कोशिश कर रहा है:
error: no matching function for call to ‘begin(std::vector<std::basic_string<char> > (&) (std::istream_iterator<std::basic_string<char> >, std::istream_iterator<std::basic_string<char> > (*) ()))’
for(auto s : strings)
^
और कई अन्य लोगों ...
मुझे लगता है कि मैं यहाँ कुछ स्पष्ट याद कर रहा हूँ, किसी को भी कृपया मदद कर सकते हैं?
[अधिकतर वेक्सिंग पार्स] देखें (http://en.wikipedia.org/wiki/Most_vexing_parse)। – chris
इससे मदद मिल सकती है: http://stackoverflow.com/questions/7007817/a-confusing-detail-about-the-most-vexing-parse – templatetypedef
समझ गया। क्या मुझे यह प्रश्न हटा देना चाहिए या इसे स्वयं जवाब देना चाहिए? – JLagana