EDIT : Turns out that the problem is that in iosfwd, it throws the exception at line 506 :
Exception thrown: write access violation. _Left was 0xCCCCCCCC.
To answer :How to Fix: Exception thrown: write access violation. _Left was 0xCCCCCCCC
I am making a program where it launches another program in its same directory that updates a text file using ShellExecute.
The program begins by taking a string using getline
and then uses ShellExecute
to launch another program that uses fstream
to update a file.
Here is the relevant part of the program:
cout << "Please enter Program Name:" << endl;
getline(cin.ignore(), a);
system("cls");
os.open("tempstring.txt");
os << a;
os.close();
LPCSTR filename = "NewProgScript.exe";
LPCSTR Location = NULL;
ShellExecute(NULL, "open", filename, NULL, Location, SW_SHOWNORMAL);
/*>> >> >> >> >> rest is irrelevant << << << << << <<*/
bool end = false;
do
{
system("cls");
is.open("tempdone.txt");
is >> x;
is.close();
if (x == 1) { end = true; }
if (x == 2) { os.open("tempdone.txt"); os << 0; os.close(); Errors Err; Err.Error(41); }
cout << "Please wait while Files Update." << endl;
Sleep(1000);
} while (end == false);
"NewProgScript.exe
" is launched here.
NewProgScript.exe code:
#include "pch.h"
#include <fstream>
#include <string>
#include <Windows.h>
#include <iostream>
using namespace std;
int main()
{
ofstream os;
ifstream is;
string a, nouse;
string Progs[20];
is.open("tempstring.txt");
getline(is, nouse);
is.close();
cout << "UPDATING DATABASE.. DO NOT EXIT!" << endl;
string name, ending, end;
ending = ".txt";
name = "Prog";
for (int count = 1; count < 20 + 1; count++)
{
end = name + to_string(count) + ending;
is.open(end);
getline(is, Progs[count]);
is.close();
}
for (int count = 1; count < 20 + 1; count++)
{
end = name + to_string(count) + ending;
if (Progs[count] == "NULL")
{
os.open("end");
os << nouse;
os.close();
os.open("tempdone.txt");
os << 1;
os.close();
Sleep(500);
exit(EXIT_SUCCESS);
}
}
os.open("tempdone.txt");
os << 2;
os.close();
}
The problem is that when this is launcher early on using ShellExecute
, it does not update the file "tempdone.txt"
It does however work when I manually click open it externaly.
How can i fix this?
P.S: sorry for the Very long post! Also I am sorry of i make dumb or naive mistakes, i am not very good yet :/