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();`
}