मैं एक std::stringचर लिखना चाहता हूं जिसे मैं उपयोगकर्ता से फ़ाइल में स्वीकार कर रहा हूं। मैंने write()विधि का उपयोग करने की कोशिश की और यह फ़ाइल को लिखता है। लेकिन जब मैं फ़ाइल खोलता हूं तो मुझे स्ट्रिंग के बजाय बक्से दिखाई देते हैं।
स्ट्रिंग केवल एक चर लंबाई एकल शब्द है। इसके std::stringलिए उपयुक्त है या मुझे चरित्र सरणी या कुछ और का उपयोग करना चाहिए।
ofstream write;
std::string studentName, roll, studentPassword, filename;
public:
void studentRegister()
{
cout<<"Enter roll number"<<endl;
cin>>roll;
cout<<"Enter your name"<<endl;
cin>>studentName;
cout<<"Enter password"<<endl;
cin>>studentPassword;
filename = roll + ".txt";
write.open(filename.c_str(), ios::out | ios::binary);
write.put(ch);
write.seekp(3, ios::beg);
write.write((char *)&studentPassword, sizeof(std::string));
write.close();`
}
std::stringलिए ठीक है।