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

You can't. You have to create a new file.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.