由于水平原因,博客大部分内容摘抄于网络,如有错误或者侵权请指出,本人将尽快修改

c/c++刷题中的输入输出

c/c++中的输入输出

#include <iostream>
using namespace std;
int main()
{
    //c语言中的输入输出
    int a, b;
    scanf("%d%d",&a,&b);
    printf("%d\n",a+b);
    //c++中的输入输出
    cin >> a >> b;
    cout << a + b << endl;
    return 0;
}

字符输入输出

#include <stdio.h>
int main()
{
    //读取一个字符并输出一个字符
    char c = getchar();
    putchar(c);
    return 0;
}
#include <stdio.h>
int main()
{
    char c;
    //读入一行字符串,输出
    while ((c = getchar()) != '\n') putchar(c);
    return 0;
}

字符串输入

#include <iostream>
using namespace std;
int main()
{
    //c 语言读入一行带空格的方法
    char s[1001];
    gets(s);
    puts(s);

    //c++ 读入一行带空格的方法
    string str;
    cin.getline(s, 1000);
    str=s;
    cout << s << endl;
    cout << str << endl;
    return 0;
}

 

posted @   小纸条  阅读(76)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~
点击右上角即可分享
微信分享提示