PAT c 字串輸入輸出

2021-10-09 11:56:05 字數 1363 閱讀 6675

printf_s

("%.1f"

,8.0

/5.0);

// "%.lf": 保留一位小數 有小數點

printf_s

("%lf"

,8.0

/5.0);

// "%lf": 輸出浮點數

#include

#include

#include

#include

#include

using

namespace std;

intmain()

} cout << ans << endl;

return0;

}

多行輸入,但是不提前告訴你輸入多少個字串,方案一與eof判斷

#include

#include

#include

#include

#include

#include

using

namespace std;

intmain()

*/ ans.

push_back

(c);

if(c ==

'\n')}

return0;

}

如果沒有空格使用 scanf().scanf 的返回值代表成功讀取了多少個值。

scanf

("%d %d"

,&a,

&b);

//成功返回2

字串輸入輸出函式

while gets name null 可檢查檔案是否結尾 while ch getchar eof gets 讀取換行符並將其丟棄,fgets 把換行符存字串裡,但每次顯示字串會顯示換行符 不足之處 fgets 是為檔案i o而設計得,在處理鍵盤輸入時就不如gets 那麼方便。它需要第二個引數來...

字串和輸入輸出

一.示例程式 include include define density 62.4 int main 該程式的新特性 1.使用乙個陣列來存放字串,可以存放40個位元組,每個位元組都可以存放乙個字元值。2.使用 s轉換說明符來處理字串輸入和輸出。3.使用預處理器定義 4.使用strlen 這個函式來...

字串輸入輸出函式

字串輸入首先要考慮的是儲存位置和儲存空間大小。例子 char name scanf s name 指標未初始化,可能指向記憶體中的任意地方,字串讀入的時候有可能覆蓋記憶體中的關鍵資料,造成程式或機器崩潰。char name 81 這種方式顯式宣告空間並進行初始化。scanf s str 函式讀入單個...