c++十分神奇,可以直接用輸入輸出流操作char陣列(int絕對不可以)#include
//c++的萬用標頭檔案
using
namespace std;
intmain()
#include
//c++的萬用標頭檔案
using
namespace std;
intmain()
這裡輸入#include
using
namespace std;
intmain()
for(i=
0;i<
3;i++
) cout
}
abc 123 !@#
輸出的結果是
說明使用cin輸入的string陣列是用char的二維陣列形式儲存的abc 123 !@#
abc 123 !@#
2--------------------------------
process exited with return value 0
press any key to continue . . .
再修改**,對a進行第二次cin輸入
輸入內容為
a 11 d
輸出的結果是#include
using
namespace std;
intmain()
for(i=
0;i<
3;i++
) cout
]
0;i<
2;i++
)for
(i=0
;i<
3;i++
) cout
]<}
說明第二次cin輸入時,會清空上次相應位置的輸入abc 123 !@#
abc 123 !@#
2a 111
a 111 !@#
@--------------------------------
process exited with return value 0
press any key to continue . . .
c++中,可以直接對乙個string整串做判別而不用寫迴圈判別單個字母
#include
using
namespace std;
intmain()
else
}
#include
using
namespace std;
intmain()
for(i=
0;i<
3;i++
)else
}}
字元陣列的輸入輸出
scanf 對字元型別有 c 和 s 兩種格式 printf 同理,下同 其中 c 用來輸入單個字元,s 用來輸入乙個字串並存在字元陣列裡。c 格式能識別空格跟換行並將其輸入,而 s 通過空格或換行來識別乙個字串的結束。示例 includeint main 輸入 tat tat tat 輸出 tat...
C C 字元陣列的輸入輸出
字元陣列就是char陣列,當維度是一維是可以當做 字串 當維度是二維時可以當成是字串陣列,即若干字串。字元陣列的輸入除了使用scanf外,還可以使用getchar或者gets 其輸出除了使用printf外,還可以使用putchar或者puts。1 scanf輸入,printf輸出 scanf對字串的...
C C 字元陣列的輸入輸出
字元陣列就是char陣列,當維度是一維是可以當做 字串 當維度是二維時可以當成是字串陣列,即若干字串。字元陣列的輸入除了使用scanf外,還可以使用getchar或者gets 其輸出除了使用printf外,還可以使用putchar或者puts。1 scanf輸入,printf輸出 scanf對字串的...