I am new to comp science so your ideas would be helpful a good deal. Personally i thought that it can be achieved using a batch script but wonder if it can be done using C++ as i want the final tool to be an .exe file which perform the above intended operation when executed.
Unfortunately, even with all the updates to cmd.exe, the fellas over at MS never figured people would do stuff like you want in pure batch script, so you'll need to write yourself a little C++ program (or use another shell interpreter) to do it.
In C++, a deque of lines is probably the easiest to modify.
#include <deque>
#include <fstream>
#include <iostream>
#include <string>
usingnamespace std;
int main()
{
deque <string> text;
string s;
// load the file
ifstream inf( filename ); // You must supply the proper filename
if (!inf) ... // Check for errors here
while (getline( inf, s ))
text.push_back( s );
if (!inf.eof()) ... // and here
inf.close();
// modify the text
text.insert(
text.begin() + linenumber, // again, you must supply the line number
string( "This is a new line of text" )
);
// rewrite the new text to file
ofstream outf( filename );
if (!outf) ...
for (deque <string> ::iterator
line = text.begin();
line != text.end();
++line)
outf << *line << '\n';
outf.close();
return 0;
}
How you get the filename and line number to insert the new line(s) is, of course, up to you. You might also want to look at the deque::insert documentation for variations.