行业知识
C/C++ 中输入字符串的几种方式
2026-11-05 09:47:52
来源:互联网转载
C/C++ 中输入字符串的几种方式:
scanf,cin,getline,getchar,cin.get,cin.getline
()C/C++ ��字符串大致是以下两种:
()char a[n] 字符数组类型
string 字符串类型
1.scanf
scanf 只能接收一个字符数组,遇 “空格”“回车”都结束
#include using namespace std;int main() { char s[10]; scanf("%s", s); cout > s; cout > s; cout