I have a .txt file that contains a lot of text. I will read the whole text file and output a new textfile with one change that is this:

The txt file that I will read could for example look like this:

Value1 Value2 Value3[]
Value4 Value5[]

What I am trying to do is to change all "[" to "x["
So the lines will look like this instead:

Value1 Value2 Value3x[]
Value4 Value5x[]


What could be the approach I will think about here ?

Recommended Answers

All 2 Replies

std::ifstream fin( "file1.txt" ) ;
std::ofstream fout( "file2.txt" ) ;
fin >> std::noskipws ;
char ch ;
while( fin >> ch )
{
  if( ch == '[' ) fout << 'x' ;
  fout << ch ;
}

That worked great.

Thanks for that solution. /j

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.