nprogram’s blog

気ままに、プログラミングのトピックについて書いていきます

初期化構文 [C++17]

初期化構文

#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    
    int test = 2;
    
    if (int x = 2; x > test)
    {
        std::cout << "xは変数testより大きい" << std::endl;
    }
    else if (x == test)
    {
        std::cout << "xは変数testと同じ値" << std::endl;   
    }
    else
    {
        std::cout << "xは変数testより小さい" << std::endl;   
    }
    
        switch (int x = 2)
    {
        case 2:
            std::cout << "xの値は" << x << "です。" << std::endl;
            break;
            
        default:
            break;
    }
}