Darth_EF 发表于 2020-11-9 23:18:20

作业 for 【C++语法】《C++快速入门》p2


#include <iostream>
#include<conio.h>
using namespace std;

int max = 1024;
int main()
{
    char flag=0,tempc;
    int i = 0;
    int tempi1=0,tempi2=0;

    while ((tempc = _getch())&& (i < max)) {
      // printf("%c", tempc);
      cout << tempc;
      if ((tempc > '0') && (tempc < '9')) {
            tempi2 = tempi2 * 10 + (tempc - '0');
            flag = 1;
      }
      else {
            if (flag) {
                tempi1 += tempi2;
                tempi2 = 0;
                flag = 0;
            }
            if (tempc == 13)break;
      }
    }
    // printf("\n%d\n",tempi1);
    cout << endl << tempi1 << endl;
    return 0;
}
很久没有写过c了,一直在写javascript,c生疏了。
我是从c入门编程的,后来写web前端开发,感觉自己也有点面向对象编程的经验了吧(心虚),于是找到了小甲鱼的c++教程看。这是在p2的结尾的一个作业。
页: [1]
查看完整版本: 作业 for 【C++语法】《C++快速入门》p2