Converting between std::string and System::String^

1
2
3
4
5
6
7
8
9
10
11
12
13
14
System::String ^toSys(string x) {
        System::String ^output = "";
	for (int i = 0; i < x.size(); i++) {
		output += x[i];
	}
	return output;
}
string toStd(System::String ^x) {
	string output = "";
	for (int i = 0; i < msclr::interop::marshal_as<string>(x).length(); i++) 
		output += x[i];
	}
	return output;
}

There are no errors for conversion either way, but when converting to a system string it takes the value of each char (e.g "48" for '0'). How can I make it use the actual characters?
I think I just did this:

1
2
std::string str1 = "manamana";
String^ str2 = gcnew String(str1.c_str());
Topic archived. No new replies allowed.