क्या open
फ़ंक्शन में कुछ प्रकार का प्रतिबंध है कि किस तरह का स्ट्रिंग मान पास किया गया है?संकलन त्रुटि: ifstream :: केवल उद्धरणों में स्ट्रिंग मान स्वीकार करता है और स्ट्रिंग चर नहीं
ifstream file;
string filename = "output.txt";
file.open(filename);
मैं एक स्ट्रिंग चर के साथ एक स्ट्रिंग मान पारित करने के लिए कोशिश की, लेकिन जब यह संकलित करने के लिए कोशिश करता है, परिणाम ...
agent.cpp:2:20: error: ofstream: No such file or directory
agent.cpp: In function ‘std::string readingline(std::string)’:
agent.cpp:11: error: aggregate ‘std::ifstream file’ has incomplete type and cannot be defined
agent.cpp: In function ‘int main()’:
agent.cpp:44: error: aggregate ‘std::ofstream writefile’ has incomplete type and cannot be defined
दूसरी ओर, जब मैं सिर्फ एक स्ट्रिंग पारित "filename.txt" जैसे उद्धरणों में मूल्य, यह ठीक संकलित करता है और ठीक चलता है।
ifstream file;
file.open("output.txt");
ऐसा क्यों है?
क्या इस समस्या को हल करने का कोई तरीका है?
क्या आपने एक char सरणी को पॉइंटर पास करने का प्रयास किया था? – neeKo
देखें [फ़ाइल नाम के लिए (i | o) fstream एक कॉन्स्ट char * पैरामीटर क्यों लेता है?] (Http://stackoverflow.com/questions/5972151/why-does-iofstream-take-a-const-char- पैरामीटर-के-ए-फाइल-नाम) –