退出输入不确定字符的循环方法

题解:主要用到getchar()函数,在while括号中添加退出的条件;

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std;

int main()
{
    int i=0,j=0;
    char c=getchar();
    char str[100];
    while(c!='\n')
    {
        str[i++]=c;
        c=getchar();
    }
    for(j=0;j<i;j++)
    {
        cout<<str[j]<<endl;
    }
    
    return 0;
}

全部评论

相关推荐

自来熟的放鸽子能手面...:等捞就好了,你这种情况被捞的概率挺大的
投递字节跳动等公司10个岗位
点赞 评论 收藏
分享
Gaynes:查看图片
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务