jeudi 8 juillet 2021

C++ if initializer

cmake_minimum_required(VERSION 3.16)
project(competitive_programming)

set(CMAKE_CXX_STANDARD 17)

add_executable(competitive_programming main.cpp)

As you see, I'm using C++ 17, and I want to use if initializer to keep the code neat,

if (auto result = right.find(second); result != right.end()){
    result->second--;
}

But the compiler does not work as is supposed to be,

The readout seems as follows:

error: expected ')' before ';' token
         if (auto result = right.find(item); result == right.end()){error: expected ')' before ';' token
         if (auto result = right.find(item); result == right.end()){

My compiler is so, I guess:

g++ (x86_64-posix-seh, Built by strawberryperl.com project) 8.3.0

Aucun commentaire:

Enregistrer un commentaire