⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 onthefly.cpp

📁 Think in C++ 第二版源码
💻 CPP
字号:
//: C03:OnTheFly.cpp

// From Thinking in C++, 2nd Edition

// Available at http://www.BruceEckel.com

// (c) Bruce Eckel 1999

// Copyright notice in Copyright.txt

// On-the-fly variable definitions

#include <iostream>

using namespace std;



int main() {

  //..

  { // Begin a new scope

    int q = 0; // C requires definitions here

    //..

    // Define at point of use:

    for(int i = 0; i < 100; i++) { 

      q++; // q comes from a larger scope

      // Definition at the end of the scope:

      int p = 12; 

    }

    int p = 1;  // A different p

  } // End scope containing q & outer p

  cout << "Type characters:" << endl;

  while(char c = cin.get() != 'q') {

    cout << c << " wasn't it" << endl;

    if(char x = c == 'a' || c == 'b')

      cout << "You typed a or b" << endl;

    else

      cout << "You typed " << x << endl;

  }

  cout << "Type A, B, or C" << endl;

  switch(int i = cin.get()) {

    case 'A': cout << "Snap" << endl; break;

    case 'B': cout << "Crackle" << endl; break;

    case 'C': cout << "Pop" << endl; break;

    default: cout << "Not A, B or C!" << endl;

  }

} ///:~

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -