首页 > 编程语言 >c/c++刷题中的输入输出

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

时间:2022-11-27 22:11:44浏览次数:33  
标签:include int 输入输出 c++ char main 刷题

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;
}

 

标签:include,int,输入输出,c++,char,main,刷题
From: https://www.cnblogs.com/clarencezzh/p/16930832.html

相关文章