fstream problem mit put()
-
Hi,
Ich möchte ein char in meinem file ändern an einer bestimmten stelle.
#include <fstream> using namespace std; int main() { ofstream out("lol.txt", ofstream::app); out.seekp(ofstream::beg); char set = 'A'; int pos = 1; out.seekp(pos); out.put(set); out.close(); }lol.txt
HkLLOIch möchte HkLLO in "HALLO" ändern
Nach den programm start:
lol.txt
HkLLO AKönnt ihr mir weiter helfen?

-
std::ios_base::appführt dazu, das jeglicher Inhalt, welcher geschrieben wird, ans Ende angefügt wird. Was du brauchst, ist eine Anweisung, welche den Dateiinhalt nicht verändert. Dies machtstd::ios_base::in. Kann man auch hier nachlesen:
http://www.cplusplus.com/reference/iostream/ofstream/ofstream.html#include <fstream> int main() { std::ofstream out("./lol.txt", std::ios_base::in); out.seekp(1); out.put('A'); return 0; }Grüssli
-
Super schnelle antwort!
Funkt. Prima!So dann Danke
