I am writing to a text file using c++ and using a batch file to open the text file and then run the corresponding exe file at the same time. My c++ code is writing a dividing underscore line and the current date and then the user would write whatever text. The issue is that when I run the batch file which opens the text file, the cursor is at the beginning of the file and I want it to start at the very end so I wouldn't have to move it myself to write text.
This is my c++ code:
#include <iostream>
#include <fstream>
#include <string>
#include <ctime>
#include <vector>
using namespace std;
string underscoreDiv (int lengthText){
string underscores;
for(int i{}; i<lengthText; i++)
{
underscores += "_";
}
return underscores + "\n";
}
struct Date
{
int year;
int month;
int day;
Date()
{
time_t t = time(0);
tm* now = localtime(&t);
year = now->tm_year + 1900;
month = now->tm_mon + 1;
day = now->tm_mday;
}
};
int main(){
fstream fileApp("C:\\Users\\trist\\OneDrive\\Documents\\Notes_application\\Notes_app.txt", ios::in | ios::app);
if(fileApp.is_open()){
string line;
string underscore;
Date date;
int count[2]={0};
underscore=underscoreDiv (80);
fileApp.clear();
fileApp<<"\n";
fileApp<<underscore<<"\n";
fileApp<<date.month<<"/"<<date.day<<"/"<<date.year<<" : ";
fileApp.clear();
fileApp.close();
}
else{
cout<<"Text file not found";
}
system("C:\\Users\\trist\\OneDrive\\Documents\\Notes_application\\Notes_app.txt");
return 0;
}
Here is my batch file
start /b C:\Users\trist\OneDrive\Desktop\projects\notes_project_app\app_proj.exe
start C:\Users\trist\OneDrive\Documents\Notes_application\Notes_app.txt
'I tried playing with the c++ code but I'm finding it hasn't been able to actually move the cursor position when the file is opened through windows. I'm having trouble trying to move the cursor to the end through the batch file. I tried doing a send key page down but I couldn't get that to work either.'
There may be some unnecessary function in the code as I'm trying to other things meanwhile.