在做算法题中碰到的关于字符串的问题

gets 和 cin 在输入字符串时的区别
如果字符串中有空格,那么cin是截至到空格为止,结束输入,gets则是全部接收

#include <stdio.h>
#include <string.h>
#include <iostream>

using namespace std;
    char s[10000];
    char s2[1000];
int main()
{

    gets(s);
    cin >> s2;
    int t = 0;
    int len,len2 ;
    len = strlen(s);
    len2 = strlen(s2);
    cout << s << endl;
    cout << s2 << endl;
    printf("%s\n%s\n", s, s2);
    printf("%d\n%d\n", len,len2);
    return 0;
}

输入:
asd asd
asd asd

输出:
asd asd
asd asd
asd asd
asd
asd asd
asd
7
3

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值