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

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

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

Console::Write

 
#include "stdafx.h"
using namespace System;
int main()
{
   // output without newline
   Console::Write("a");
   Console::Write("b");
   Console::Write("c");
   // newline alone
   Console::WriteLine();
   // output with format string
   Console::WriteLine("Fourscore and {0} years ago.", 7);
   // output with direct types
   Console::WriteLine(7);
   Console::WriteLine( 1.05);
   Console::WriteLine("A");
}


Console::WriteLine

 
#include "stdafx.h"
using namespace System;
int main()
{
   // output without newline
   Console::Write("a");
   Console::Write("b");
   Console::Write("c");
   // newline alone
   Console::WriteLine();
   // output with format string
   Console::WriteLine("Fourscore and {0} years ago.", 7);
   // output with direct types
   Console::WriteLine(7);
   Console::WriteLine( 1.05);
   Console::WriteLine("A");
}


Read from console

 
#include "stdafx.h"
using namespace System;
int main()
{
   String^ str;
   while ((str = Console::ReadLine()) != nullptr)
   {
      Console::WriteLine( str->ToUpper() );
   }
}


Using Console::WriteLine to output to console

 

#include "stdafx.h"
#using <mscorlib.dll>
using namespace System;
enum { ONE = 1, TWO, THREE, FOUR, FIVE = 5, SIX };
int main(void) {
    Console::WriteLine(ONE);
    Console::WriteLine(TWO);
    Console::WriteLine(THREE);
    Console::WriteLine(FIVE);
    Console::WriteLine(SIX);
    return 0;
}