••FORM STRING TO NORMAL STRING••

I have looked all over the internet and tried every thing I could; I can not figure out how to convert System::String to the normal std::string.

Here is my code so far:
1
2
3
4
5
6
7
8
9
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
				string saved;
				string setsave;
				fstream text;
				struct stat buf;
				if (stat(saved.c_str(), &buf) == -1){
					this->richTextBox2->Text = "The file could not be made.\nMake sure you did not use / \ : * ? \" < > | in the file name. ";
				}
		 }




For anyone who has the same question here is a sample:

1
2
3
4
5
6
pin_ptr<const wchar_t> p = PtrToStringChars(this->textBox1->Text);   //Changes text box text to wchar_t
wstring s(p);                                                        //Changes p to wstring
string ss( s.begin(), s.end() );                                    //changes s to normal string
char *sss = (char*)ss.c_str();                                      //changes ss to char
System::String^ bbb = gcnew System::String(sss);                    //changes sss to System::String
this->button3->Text = bbb;                                        //shows the entered text (from textBox1) in button3. 
Last edited on
1
2
3
System::String^ b = gcnew System::String(buffer->c_str());
				 pin_ptr<const wchar_t> p = PtrToStringChars(b);
				 std::wstring s(p);

or http://msdn.microsoft.com/en-US/library/1b4az623(v=vs.80).aspx
It says buffer and PtrToStringChars are unidentified.
buffer was just a std::string, use whatever System::String you want to convert. For PtrToStringChars include vcclr.h
I get the same errors. Were you telling me to change buffer to std::string or System::String because I tried both and nether work.

Is there an easier way to just turn the textbox string into a char array?
Wait sorry just an error with buffer; PtrToStringChars is now working.
Try pin_ptr<const wchar_t> p = PtrToStringChars(this->richTextBox2->Text);
That works fine, but I still need a string and I have no idea how to to convert it. I have tried many different things. By the way what include file do I use to use CString?
I already showed you std::wstring s(p);
Okay. Thank you. I think I can handle it from here.

For anyone who has the same question here is a sample:

1
2
3
4
5
6
pin_ptr<const wchar_t> p = PtrToStringChars(this->textBox1->Text);   //Changes text box text to wchar_t
wstring s(p);                                                        //Changes p to wstring
string ss( s.begin(), s.end() );                                    //changes s to normal string
char *sss = (char*)ss.c_str();                                      //changes ss to char
System::String^ bbb = gcnew System::String(sss);                    //changes sss to System::String
this->button3->Text = bbb;                                        //shows the entered text (from textBox1) in button3. 


Topic archived. No new replies allowed.