std::stringKullanıcıdan kabul ettiğim bir değişkeni bir dosyaya yazmak istiyorum . write()Yöntemi kullanmayı denedim ve dosyaya yazıyor. Ama dosyayı açtığımda dize yerine kutular görüyorum.
Dize yalnızca değişken uzunluklu tek bir kelimedir. Bunun std::stringiçin uygun mu yoksa bir karakter dizisi falan mı kullanmalıyım.
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::stringbunun için iyidir.