Convert System string to standard?

I'm having a bit of trouble here. I'm trying to get information from a text box, with which to put into a string which then will output to a file. The first part seems to have parsed correctly but at the = between shop to shop and the code that gets the text/combo box string there's an error:

"Operand types are std;;string = System::String ^"

Now, I have never used the system namespace before. How would I convert system::String to standard? If I try using string ^ ShopToShop it says "A handle to a non managed class is not allowed"

If it's any help, the program is being made via Visual Studio 2015 community + windowsforms

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) 
{
	using namespace std;

	string ShopToShop;
	string CashCredit;
	string ItemSold;
	string Cost;
	string Date;

	ShopToShop = comboBox1->SelectedItem->ToString();

	ofstream output;
	output.open("Daily Totals");
	
}
};
}
Last edited on
I know how to use google, I was really looking for more of a why and a more detailed explanation than some of those links. What the actual difference is between a system string and a regular one, etc.
How would I convert system::String to standard?
I was really looking for more of a why

All I saw was "how", but as for "why"...
It looks like System::String was introduced in .NET framework 1.1 on 2003-04-24. And it looks like in 1985 std::string was introduced to C++ http://en.cppreference.com/w/cpp/language/history . So honestly, I am not really sure why. I could speculate some reasons for trying to not rely on the standard C++ library, but that is the best I can come up with.

The main difference between the two is the structure of their classes (the methods, private data, public data, etc.). Microsoft maintains one, whereas the other is public knowledge based on the ISO C++ standard. Anyone could implement the given description of a std::string in their own implemenation of the ISO C++ standard if they really wanted to. Microsoft keeps their API sources closed off from the public.
Last edited on
closed account (48T7M4Gy)
It's all about Microsoft trying to corner the market, not unlike MFC Was. Best work around it because the cornering doesn't work as they are finding out and are smart enough to adapt to by falling in line at last.

(Unless of course you are working on legacy stuff)
Last edited on
What the actual difference is between a system string and a regular one, etc.

A System::String is a managed CLR ( .NET ) class and std::string is a native C++ class, so two totally different species.
Thanks you guys, I solved it with this function (still working on where to put that if statement lol)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
			 static std::string toStandardString(System::String^ string)
			 {
				 using System::Runtime::InteropServices::Marshal;

				 if (string->Length == 0 || string->Length < 0)
				 {
					 MessageBox::Show("No field can be empty");

				 }

				 System::IntPtr pointer = Marshal::StringToHGlobalAnsi(string);
				 char* charPointer = reinterpret_cast<char*>(pointer.ToPointer());
				 std::string returnString(charPointer, string->Length);
				 Marshal::FreeHGlobal(pointer);
				 

				 return returnString;
			 }


It's all about Microsoft trying to corner the market, not unlike MFC Was. Best work around it because the cornering doesn't work as they are finding out and are smart enough to adapt to by falling in line at last.

(Unless of course you are working on legacy stuff)


Gee, another proprietary M$ langauge? So there's C#, VB .NET, what about F#?

How come I can use C++ code (standard stuff) in source files along with propretiary M$ stuff? They use the same C++ file type? (Using VS 2015 Community)

Fascinating stuff really.
How come I can use C++ code (standard stuff) in source files along with propretiary M$ stuff? They use the same C++ file type? (Using VS 2015 Community)
Apparently it's an entirely different language from C++ that just happens to share some of the syntax, so either the implementation provides managed equivalents of standard C++ classes and functions, presumably so porting existing C++ code to .NET is straightforward, OR the C++/CLI compiler is feature-complete with respect to the C++ parts, so C++ is able to share its standard headers without modifications.
Topic archived. No new replies allowed.