原文:
1、cin
cin遇到空格或回車鍵停止,只能輸入沒有空格的字串,當輸入中含有空格,則只能輸出空格之前的字元;
#include#includeusing namespace std;
int main()
當輸入:hello world 時,遇到回車鍵輸出:hello;
7,、讓scanf可以接收空格,遇到回車鍵結束(有時與getchar()配合使用);
這裡主要介紹乙個引數,%[ ],這個引數的意義是讀入乙個字元集合。[ ]是個集合的標誌,因此%[ ]特指讀入此集合所限定的那些字元,比如%[a-z]是輸入大寫字母,一旦遇到不在此集合的字元便停止。如果集合的第乙個字元是「^」,這說明讀取不在「^「後面集合的字元,即遇到」^「後面集合的字元便停止。此時讀入的字串是可以含有空格的。
#include using namespace std;
int main()
當輸入:hello world 時,遇到回車鍵輸出:hello world;
(2)要加getchar() 的;
#include using namespace std;
int main()
{ int n;
char a[100];
cin>>n;
getchar();//吸收換行符,一定要加
for(int i=0;i輸入:11
hello world
輸出:hello world;
C C 字串輸入輸出
一 c語言 一 1 include 2void main 3 二 1 include 2void main 3 注 下面測試中 a 與 b 一樣 1 include 2void main 3 最後一位儲存的是 0 5 puts a 6char b 5 7 b 0 a 8 b 1 b 9 b 2 c ...
c c 字元 字串輸入輸出
1.scanf 1.1 輸入字元 char ch scanf c ch 注意字元前面的取位址符 1.2 輸入字串 char str 15 scanf s str char pstr scanf s pstr 1 scanf 在輸入字串時,不讀入空格和回車,在讀入空格或回車時,輸入結束 2 輸入字串長...
字串輸入輸出函式
while gets name null 可檢查檔案是否結尾 while ch getchar eof gets 讀取換行符並將其丟棄,fgets 把換行符存字串裡,但每次顯示字串會顯示換行符 不足之處 fgets 是為檔案i o而設計得,在處理鍵盤輸入時就不如gets 那麼方便。它需要第二個引數來...