When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
1 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
you need to give it a mode i believe so it would be std::fstream file("password.txt", file.in | file.out);
Perhaps just for my own curiosity, where in the opened file did you hope file<<encode(Password,Password.length()); would actually write to?
Btw, std::fstream by default opens the file for reading and writing (see https://en.cppreference.com/w/cpp/io/basic_fstream/basic_fstream).
Wonder if the getline is causing a badbit or failbit which needs to be cleared.
what happens if after the getline and before the file << encode..., you call file.clear();?
That's just intellisense, if the file doesn't exist you also need std::fstream::app
std::fstream file("password.txt", std::fstream::in | std::fstream::out | std::fstream::app);
or std::ios::in/out/app
You sure the app is looking in the write place then?
What are you using for your IDE?
Well using std::fstream file("password.txt", std::ios::in | std::ios::out | std::ios::app);
Should always make sure that the file is opened or makes a new file. so you know if it makes a new empty file you'll have put it in the wrong place
int main() {
//open the file
std::fstream file("password.txt", std::ios::in | std::ios::out | std::ios::app);
std::string Password;
//get the first line of the file
std::getline(file, Password, '\n');
file.clear();
file.seekp(0, std::ios::end);
file << encode(Password, Password.length());
}
That should work