Answer the question
In order to leave comments, you need to log in
Why does System.AccessViolationException appear in Visual Studio 2010?
There is this code:
#include "stdafx.h"
#include <iostream>
#include <conio.h>
using namespace std;
using namespace System;
void reverse (char * str, int count = 0);
int main(array<System::String ^> ^args)
{
char * str = "Hello";
reverse (str, 3);
cout<<str;
_getch();
return 0;
}
void reverse (char * str, int count)
{
char temp;
if (count == 0)
count = strlen(str) - 1;
for (int i = 0, j = count; i < j; i++, j--)
{
temp = str[i];
str[i] = str[j];
str[j] = temp;
}
}
Answer the question
In order to leave comments, you need to log in
Try char * str = "Hello"; replace with char str[] = "Hello";
I suspect that the string "Hello" during assembly is placed in a section without write permissions, you use this pointer and try to write to the same RO area.
Why is .NET here at all? Why are you creating C++/Cli projects at all if you don't need to? Why do you need a CLR project, do Win32, then it will be easier to understand you and no matter how errors you do not understand will fly out. It's hard to believe that the book you mentioned asks you to create CLR projects. And with translations into Russian, a common problem is a lot of typos.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question