小工具知识网

当前位置: 首页 > 行业知识 > C/C++ 中输入字符串的几种方式

行业知识

C/C++ 中输入字符串的几种方式

2026-11-05 09:47:52 来源:互联网转载

C/C++ 中输入字符串的几种方式:

scanf,cin,getline,getchar,cin.get,cin.getline

()

C/C++ ��字符串大致是以下两种:

()
  1. char a[n] 字符数组类型

  1. string 字符串类型


1.scanf

scanf 只能接收一个字符数组,遇 “空格”“回车”都结束

#include using namespace std;int main() {    char s[10];    scanf("%s", s);    cout > s;    cout > s;    cout 

上一篇:紧急应对!手机进水无法开机解决方案!

下一篇:一文读懂大模型 Agent 架构,详解Profile,Memory,Planning,Action模块作用