C 如何從控制台讀取輸入和輸出

2021-10-07 11:24:57 字數 761 閱讀 7248

// console 是 namespace system 的乙個類 

string str = console.

readline()

;// 讀入一行字串,去掉其中的讀入的換行符

int a = console.

read()

;// 讀入下乙個輸入,按下回車後響應,回車輸入的字元也進入快取區但本次不會讀入

// vs 命令列下,一次回車會輸入\r\n兩個字元,滿足兩次read()

輸出字串

console.writeline("哈嘍!");

輸出顯示若干個項:

console.writeline(" 年.", str, year);

在c#控制台程式中提供了兩種方法讓使用者輸入所需資料,它們是有console類提供的靜態方法。

static

int read();

要讀取單個字元,則使用read()方法,它等待使用者輸入乙個鍵,然後返回結果。字元作為int型別的值返回,所以要顯示字元就必須轉換為char型別。

static

string readline();

要讀取一串字元,則使用readline()方法。該方法一直讀取字元,直到使用者按下enter鍵,然後將它們返回到string 型別的物件中

C 從控制台輸入年曆,控制台輸出月日曆

1.根據年月日計算星期數的方法 private static intgetweekbyday int year,int month,int day 2.計算指定月數的天數 private static intgetdaysbymonth int year,int month 3.實現月曆 priva...

讀取控制台輸出

在新建工程窗體中新增button1 memo1 unit unit1 inte ce uses windows,messages,sysutils,variants,classes,graphics,controls,forms,dialogs,stdctrls,extctrls type tfor...

C 控制台讀取和輸出函式

c中puts 函式 用來向標準輸出裝置 螢幕 寫字串並換行,其呼叫方式為,puts s 其中s為字串字元 字串陣列名或字串指標 功 能 送一字串到流stdout中 用 法 int puts char string 程式例 include int main void 說明 puts 和 printf ...