i found this code online and im trying to get it to overwrite
the original file instead of printing to screen but i have to admit
its too advanced for me can anyone help please

#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <iterator>

using namespace std;

int main()
{
  vector <string> array;

  std::ostream_iterator< string > output ( cout, "\n" );

  ifstream read ( "letters3.txt" );
  string line;
  while ( getline ( read, line, '\n' ) )
  {
        array.push_back ( line );    
  }
  read.close(); 
  sort ( array.begin(), array.end() ); 

  std::vector< string >::iterator endLocation;
  endLocation = std::unique ( array.begin(), array.end() );

    std::copy ( array.begin(), endLocation, output ); 
  
   
  cin.get();
  return 0;
}

can anyone help please

Sure. I added the CODE TAGS you ignored, which are described
1) in the Rules you were asked to read when you registered
2) in the text at the top of this forum
3) in the announcement at the top of this forum titled Please use BB Code and Inlinecode tags
4) in the sticky post above titled Read Me: Read This Before Posting
5) any place CODE tags were used
6) Even on the background of the box you actually typed your message in!

I don't fully understand your question, do you just want to overwrite a file on your harddisk?

OP want to write back sorted text content into same file.
>i found this code online and im trying...
--Try to learn stream classes.

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.