c++如何输入字符数组以回车结束

求代码

可以用gets函数解决,代码如下:

温馨提示:答案为网友推荐,仅供参考
第1个回答  2015-03-17

可以用gets函数解决,代码如下:

#include<stdio.h>
int main()
{
    char str1[20];
    printf("请str1输入字符串(gets方式):\n");
    gets(str1);
    printf("下面输出str1(puts方式):\n");
    puts(str1);
    return 0; 
}

本回答被提问者采纳
第2个回答  2015-03-17
#include <string>

#include <iostream>
using namespace std;

void main()
{
string line;
getline(cin, line);
cout << line << endl;
}本回答被网友采纳
第3个回答  2015-03-17
#include <iostream>
using namespace std;
int main() {
char arr[20];
cin >> arr;
cout << arr;
}
相似回答