c++ - Compile error when using std::cout between if/elseif statements -


i wondering why compile error when try use std::cout in between, say, if statement , else if statement. example:

if (condition) {body} std::cout << "hello world" << std::endl; else if (condition) {body} 

gives error

error: 'else' without previous 'if' 

let me right first:
want execute cout statement in between conditional no matter whether condition met or not, i.e. no matter whether body of if got executed or not.

as previous commenters noted, cannot place between end of scope of if-block , else keyword.

what approaching splitting if-else-if block 2 separate if-blocks:

if (condition1) {     body1 } cout << "hello world" << endl; if (!condition1 && condition2) {     body2 } 

Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -