Hello everyone, I'm new here and I need some help. I'm having error like:
Debug Assertion Failed!
Program: C:\WINDOWS\SYSTEM3MSVCP110D.all
File: C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xstring
Expression: invalid null pointer
And then suggestions to see C++ documentation...
heres where it drops error:
void StringtoString (String ^ miestasi, string & os)
{
using namespace Runtime::InteropServices;
const char* chars = (const char*) (Marshal::StringToHGlobalAnsi(miestasi)).ToPointer();
os = chars;
Marshal::FreeHGlobal(IntPtr((void*)chars));
}
and here:
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
string miestas[20], os;
String ^ miestasi;
int il[20], al[20], val[20], kaina[20], i;
StringtoString(miestasi,os);
fr << os << endl;
}
String ^ miestasi; doesn't create a string. You would need to do something like String^ string1 = "This is a string created by assignment.";.
I'm making a windows form and I'll type it by myself.
Maybe... So how should it look then???
Last edited on
Something like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace System;
using namespace System::Runtime::InteropServices;
void StringToString(System::String ^ managed, std::string & native)
{
char * stringPtr = (char *)Marshal::StringToHGlobalAnsi(managed).ToPointer();
native = std::string(stringPtr);
Marshal::FreeHGlobal(IntPtr(stringPtr));
}
int main(array<System::String ^> ^args)
{
System::String^ managedString = "Hello World";
std::string nativeString;
StringToString(managedString, nativeString);
std::cout << nativeString << std::endl;
return 0;
}
|
NB:This is for a CLR Console Application Project and is untested
Or
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
#include "stdafx.h"
#include <iostream>
#include <string>
#include <msclr\marshal_cppstd.h>
using namespace System;
using namespace msclr::interop;
void StringToString(System::String ^ managed, std::string & native)
{
msclr::interop::marshal_context context;
native = context.marshal_as<std::string>(managed);
}
int main(array<System::String ^> ^args)
{
System::String^ managedString = "Hello World";
std::string nativeString;
StringToString(managedString, nativeString);
std::cout << nativeString << std::endl;
return 0;
}
|
Last edited on