Replace some elements in text file.

Hi everyone!
I have a text file, like that:

(A1*	
*	
*	
*A1)	
*	
(AM-MNR*AM-MNR)	
(V*V)	
(C-A1*	
*	
*	
*	
C-A1)

Now, I would like to replace some elements, follow the rule:
-(A1* ---> B- A1
- characters "*" following is replace by I-A1
- *A1) ---> I- A1

The output like that:

B- A1	
I- A1	
I- A1	
I- A1	
*	
B-AM-MNR
(V*V)	
B-C-A1	
I-C-A1	
I-C-A1
I-C-A1	
I-C-A1

How can I do now?

My text file have 220 663 lines and 858 995 characters (I used Linux commands : \wc to count them. If I use array to store data, I think it's too large array.
But if use fstream, I dont know to access each element in stream to compare and replace. I dont know How many labels such as: A1, C- A1, AM- MNR... which I have to replace.

Please give me some instructions. Many thanks.
Last edited on
hmm..you can try posting what you've got so far(just the fil. But I guess you can try looking at fstream(see reference: http://www.cplusplus.com/reference/ ) yourself. BTW, you can actually use yourstream.peek() to see if what value would be coming next. :)
Topic archived. No new replies allowed.