Console.OpenStandardInput 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
擷取標準輸入資料流。
多載
OpenStandardInput() |
擷取標準輸入資料流。 |
OpenStandardInput(Int32) |
擷取標準輸入資料流,設定為指定的緩衝區大小。 |
OpenStandardInput()
擷取標準輸入資料流。
public:
static System::IO::Stream ^ OpenStandardInput();
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public static System.IO.Stream OpenStandardInput ();
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
[System.Runtime.Versioning.UnsupportedOSPlatform("android")]
[System.Runtime.Versioning.UnsupportedOSPlatform("ios")]
[System.Runtime.Versioning.UnsupportedOSPlatform("tvos")]
public static System.IO.Stream OpenStandardInput ();
public static System.IO.Stream OpenStandardInput ();
[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
static member OpenStandardInput : unit -> System.IO.Stream
[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("android")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("ios")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("tvos")>]
static member OpenStandardInput : unit -> System.IO.Stream
static member OpenStandardInput : unit -> System.IO.Stream
Public Shared Function OpenStandardInput () As Stream
傳回
標準輸入資料流。
- 屬性
範例
在下列程式碼中,說明了如何使用 OpenStandardInput
方法。
using namespace System;
using namespace System::Text;
using namespace System::IO;
int main()
{
Stream^ inputStream = Console::OpenStandardInput();
array<Byte>^bytes = gcnew array<Byte>(100);
Console::WriteLine( "To decode, type or paste the UTF7 encoded string and press enter:" );
Console::WriteLine( "(Example: \"M+APw-nchen ist wundervoll\")" );
int outputLength = inputStream->Read( bytes, 0, 100 );
array<Char>^chars = Encoding::UTF7->GetChars( bytes, 0, outputLength );
Console::WriteLine( "Decoded string:" );
Console::WriteLine( gcnew String( chars ) );
}
using System;
using System.Text;
using System.IO;
public class Decoder {
public static void Main() {
Stream inputStream = Console.OpenStandardInput();
byte[] bytes = new byte[100];
Console.WriteLine("To decode, type or paste the UTF7 encoded string and press enter:");
Console.WriteLine("(Example: \"M+APw-nchen ist wundervoll\")");
int outputLength = inputStream.Read(bytes, 0, 100);
char[] chars = Encoding.UTF7.GetChars(bytes, 0, outputLength);
Console.WriteLine("Decoded string:");
Console.WriteLine(new string(chars));
}
}
open System
open System.Text
let inputStream = Console.OpenStandardInput()
let bytes = Array.zeroCreate<byte> 100
Console.WriteLine "To decode, type or paste the UTF7 encoded string and press enter:"
Console.WriteLine "(Example: \"M+APw-nchen ist wundervoll\")"
let outputLength = inputStream.Read(bytes, 0, 100)
let chars = Encoding.UTF7.GetChars(bytes, 0, outputLength)
Console.WriteLine "Decoded string:"
Console.WriteLine(string chars)
Imports System.Text
Imports System.IO
Public Class Decoder
Public Shared Sub Main()
Dim inputStream As Stream = Console.OpenStandardInput()
Dim bytes(100) As Byte
Console.WriteLine("To decode, type or paste the UTF7 encoded string and press enter:")
Console.WriteLine("(Example: ""M+APw-nchen ist wundervoll"")")
Dim outputLength As Integer = inputStream.Read(bytes, 0, 100)
Dim chars As Char() = Encoding.UTF7.GetChars(bytes, 0, outputLength)
Console.WriteLine("Decoded string:")
Console.WriteLine(New String(chars))
End Sub
End Class
備註
當方法變更標準輸入資料流程之後,就可以使用這個方法來重新產生它 SetIn 。
另請參閱
適用於
OpenStandardInput(Int32)
擷取標準輸入資料流,設定為指定的緩衝區大小。
public:
static System::IO::Stream ^ OpenStandardInput(int bufferSize);
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public static System.IO.Stream OpenStandardInput (int bufferSize);
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
[System.Runtime.Versioning.UnsupportedOSPlatform("android")]
public static System.IO.Stream OpenStandardInput (int bufferSize);
public static System.IO.Stream OpenStandardInput (int bufferSize);
[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
static member OpenStandardInput : int -> System.IO.Stream
[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("android")>]
static member OpenStandardInput : int -> System.IO.Stream
static member OpenStandardInput : int -> System.IO.Stream
Public Shared Function OpenStandardInput (bufferSize As Integer) As Stream
參數
- bufferSize
- Int32
此參數沒有任何作用,但其值必須大於或等於零。
傳回
標準輸入資料流。
- 屬性
例外狀況
bufferSize
小於或等於零。
備註
當方法變更標準輸出資料流程之後,就可以使用這個方法來重新產生它 SetIn 。