0

How can I delete the old entries from the .txt file and replace them with the new ones?

Like : I have a text file that has "123" in it, when I try to change the txt file it just adds the new text, I add "abc" to it and it comes out "123abc", but I want it to just be "abc" in it.

#include <iostream>
#include <fstream>      
using namespace std;
#include <stdio.h>

int main () {
    string text;

    fstream fails;
    fails.open("Teksts.txt",ios::out | ios::app);

      cout << "Enter word you want to replace the old entry with: ";
        cin >> text;

        fails << text;
    fails.close();

  return 0;
  std::cin.get();
}
2
Contributors
2
Replies
10
Views
2 Years
Discussion Span
Last Post by latrodectuss.imvu
0

So I changed the "ios::out | ios::app" to just "

fails.open("Teksts.txt", ios::out);

Doing this it dose get rid of the old entry, and replaces it with the new one, or just creates a new file with the new entry?

Why isthis good/bad to use? Except ofcurse thet I can only "delete" all, insted of one entry.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.