I'm having a problem with taking the user input from a richtextbox in Unicode and writing it to a Unicode text file.

I'm able to read a different Unicode file and write it to the new file, but when it comes to writing the contents of the richtextbox to the new file, nothing appears.

I've tried debugging it, and I can see that the wstring is assigned correctly, I just can't see why this won't write to file.

What am I doing wrong?

private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
	std::wifstream inFile(L"testin.txt", std::ios::in | std::ios::binary);
	std::wofstream outFile(L"test.txt", std::ios::app | std::ios::binary);
	std::wstring my_string;
		outFile<<my_string + L"\x0a\x00";

	const wchar_t* chars = (const wchar_t*)(Marshal::StringToHGlobalUni(richTextBox1->Text)).ToPointer();
	std::wstring str1(chars);
	outFile<<str1 + L"\x0a\x00";

Thanks in advance!


Thanks for the reply.

I looked up streamWriter as you suggested and have implemented it, and now it works perfectly, thanks!

System::IO::StreamWriter^ swFromFileTrueUTF16 = gcnew System::IO::StreamWriter(L"test.txt",true, System::Text::Encoding::Unicode);
	swFromFileTrueUTF16->Write(richTextBox1->Text + L"\x0d\x0a");
This question has already been answered. Start a new discussion instead.