看起来C++/CX没有StringBuilder类或其等价物,所以我想我们需要使用STL来做到这一点?
这是我第一个C++/CX应用程序。用户在TextBox中输入一些文本,然后点击ENTER按钮,文本被附加到名为"console"的TextBlock中。这段代码确实可以工作,但最佳实践是什么呢?
public ref class MainPage sealed
{
public:
MainPage();
protected:
virtual void OnNavigatedTo(Windows::UI::Xaml::Navigation::NavigationEventArgs^ e) override;
private:
std::wstring _commandLine;
std::wstring _consoleText;
void Button_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
};
...
void HelloConsole::MainPage::Button_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
this->_commandLine = this->InputLine->Text->Data();
this->_commandLine.append(L"\n");
this->_consoleText += this->_commandLine;
this->InputLine->Text = "";
this->OutputConsole->Text = ref new Platform::String(_consoleText.c_str());
}