Jeanine already suggested that an antivirus or other
security program may be blocking it. She also suggested
that you set your directory as an exclusion in any AV/AM
software you re running. Have you tried that?
As further exploration along these lines, provide the
following info:
(1) What AV/AM/IS software are you using?
(2) Have you tried executing your program with
the security software temporarily disabled?
Some security software can be very aggressive when
analyzing unknown programs. As a result they sometimes
trigger a false positive - identifying the program
as possibly malicious when it isn't. When it does
that it may block access to the file in question.
I have seen this happen a number of times with very
small sample programs that I was building. When the
program was altered by adding or changing code, the
false positive detection disappeared.
When you change the string in your program you change
the object code that is generated, and that may lead to
a different assessment of the exe by the security software.
In addition to testing with your security software
briefly turned off, also experiment with the string
that appears to be creating issues while adding
some additional code to the source. Even if it
isn't needed for the sample itself. For example:
#include<iostream>
using namespace std;
int main()
{
int dummy[10] = {0};
char str[] = "This is a sample string";
return 0;
}
Or try this variation which uses a read-only
string instead of the array in your example:
#include<iostream>
using namespace std;
int main()
{
//char str[] = "This is a sample string";
const char *str = "This is a sample string";
return 0;
}
- Wayne