• C/C++输入输出


    一、C语言:

     1、输入

    ①、scanf

    遇到空格、回车和Tab键停止;

    自动在输入字符串末尾加结束符;

    #include <stdio.h>
    int main(void){
        int a,b,c;
        printf("input a,b,c
    ");
        scanf("%d%d%d",&a,&b,&c);
        printf("a=%d,b=%d,c=%d",a,b,c);
        return 0;
    }

    ②、gets

    遇到回车停止;

    自动在输入字符串末尾加结束符;

    #include <stdio.h>
    
    int main()
    {
       char str[50];
    
       printf("请输入一个字符串:");
       gets(str);
    
       printf("您输入的字符串是:%s", str);
    
       return(0);
    }

    2、输出

    ①、printf

    #include <stdio.h>
     
    int main ()
    {
       int ch;
       for( ch = 75 ; ch <= 100; ch++ ) {
          printf("ASCII 值 = %d, 字符 = %c
    ", ch , ch );
       }
       return(0);
    }

    ②、puts

    #include <stdio.h>
    #include <string.h>
    
    int main()
    {
       char str1[15];
       char str2[15];
    
       strcpy(str1, "RUNOOB1");
       strcpy(str2, "RUNOOB2");
    
       puts(str1);
       puts(str2);
       
       return(0);
    }

    二、C++

    1、输入

    ①、cin

    #include <iostream>
     
    using namespace std;
     
    int main( )
    {
       char name[50];
       cout << "请输入您的名称: ";
       cin >> name;
       cout << "您的名称是: " << name << endl;
     
    }

    2、输出

    ①、cout

    #include <iostream>
     
    using namespace std;
     
    int main( )
    {
       char str[] = "Hello C++";
       cout << "Value of str is : " << str << endl;
    }



    长风破浪会有时,直挂云帆济沧海!
    可通过下方链接找到博主
    https://www.cnblogs.com/judes/p/10875138.html
  • 相关阅读:
    LM NTML NET-NTLM2理解及hash破解
    HTML转义字符&url编码表
    ZooKeeper未授权漏洞
    阉割版BBBlack安装Debian
    在ANTMINER(阉割版BeagleBone Black)运行Debain
    Ubuntu/Debian下通过Apt-get简单安装Oracle JDK
    [Linux]几个armhf的ubuntu源
    [Ubuntu]管理开机启动项的软件
    CentOS搭建NFS服务
    [C#]SharpSSH-一个可以使用SSH连接的.NET库
  • 原文地址:https://www.cnblogs.com/judes/p/15023333.html
Copyright © 2020-2023  润新知