Visual C++ .NET/Development/StringWriter — различия между версиями

Материал из .Net Framework эксперт
Перейти к: навигация, поиск
м (1 версия)
 
(нет различий)

Версия 15:31, 26 мая 2010

Convert StringWriter to String

 
#include "stdafx.h"
#using "System.Windows.Forms.dll"
using namespace System;
using namespace System::IO;
using namespace System::Text;
using namespace System::Windows::Forms;
int main()
{
   StringWriter^ sw = gcnew StringWriter();
   sw->WriteLine("asdf");
   sw->Write("asdf\n");
   sw->WriteLine();
   String^ jambo = "asdf";
   String^ s = String::Format("{0}, {1}.", jambo, jambo);
   sw->WriteLine(s);
   sw->Write("Make a wish, {0}, {0}.", jambo);
   s = "asdf.\n";
   String::Concat(s, "asdf?");
   sw->WriteLine(s);

   StringBuilder^ sb = gcnew StringBuilder();
   sb->Append("asdf\n");
   sw->WriteLine(sb);
   // The resulting string might be displayed to the user in a GUI
   MessageBox::Show(sw->ToString(), "Poetry", MessageBoxButtons::OK);
}


Using StringWriter to write string

 
#include "stdafx.h"
#using "System.Windows.Forms.dll"
using namespace System;
using namespace System::IO;
using namespace System::Text;
using namespace System::Windows::Forms;
int main()
{
   StringWriter^ sw = gcnew StringWriter();
   sw->WriteLine("asdf");
   sw->Write("asdf\n");
   sw->WriteLine();
   String^ jambo = "asdf";
   String^ s = String::Format("{0}, {1}.", jambo, jambo);
   sw->WriteLine(s);
   sw->Write("Make a wish, {0}, {0}.", jambo);
   s = "asdf.\n";
   String::Concat(s, "asdf?");
   sw->WriteLine(s);

   StringBuilder^ sb = gcnew StringBuilder();
   sb->Append("asdf\n");
   sw->WriteLine(sb);
   // The resulting string might be displayed to the user in a GUI
   MessageBox::Show(sw->ToString(), "Poetry", MessageBoxButtons::OK);
}