Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 132,628 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,038 people online right now. Registration is fast and FREE... Join Now!




How to realize inserting code automatically?

 
Reply to this topicStart new topic

How to realize inserting code automatically?

crammer008
post 26 Mar, 2006 - 08:05 PM
Post #1


New D.I.C Head

*
Joined: 9 Feb, 2006
Posts: 14


My Contributions


Dear all,

I have a statistical software which will produce an intermediate .CPP file.

But this CPP file has not timing function. So I have to insert the following lines into the file at the end of the main() function.
CODE

   cout<<endl;
   cout<<"Clock ticks: "<<clock()<<";  Seconds: "<<clock()/CLOCKS_PER_SEC << endl;


The boring job is that I have to insert the lines and compile the file for 100 times if I plan to use the software for 100 times. So my question is how to construct a function to insert the above lines into the exact position of the .CPP file automatically.

Thanks for your guidance!

Crammer008
User is offlineProfile CardPM

Go to the top of the page

Mrafcho001
post 27 Mar, 2006 - 01:26 PM
Post #2


D.I.C Addict

Group Icon
Joined: 1 Nov, 2005
Posts: 753



Thanked 5 times

Dream Kudos: 120
My Contributions


Seems simple..

Read the file into a string, search for the main function and then look for the end of it.

Of course youll have to make sure its the closing bracket of main that you insert the code before. So you'll have to go through the entire main function looking for opening brackets and matching them with closing brackets. And when there is an unmathed closing bracket than that'd have to be the main's closing bracket.
User is offlineProfile CardPM

Go to the top of the page

crammer008
post 28 Mar, 2006 - 02:49 AM
Post #3


New D.I.C Head

*
Joined: 9 Feb, 2006
Posts: 14


My Contributions


Thank you very much:)
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/23/08 03:41AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month