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!

Recommended Answers

All 2 Replies

Can you use a StreamWriter?
Please read the statement about Unicode at that link.


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");
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.