no else for corresponding if

P

pentiumPunk

for some reason i thought i could have more if statements than else
statements.

if (!inputFile)
{
cerr<<"file not found";
}

if (something)
{
do operation;
}

else
{
do somethingElse;
}

in g++, i get an error message saying "parse error before else" which
translated to visual c++ means not same amout of elses as if's. i didnt know
that was illegal. was i wrong?
 
J

Jon Bell

for some reason i thought i could have more if statements than else
statements.

if (!inputFile)
{
cerr<<"file not found";
}

if (something)
{
do operation;
}

else
{
do somethingElse;
}

in g++, i get an error message saying "parse error before else" which
translated to visual c++ means not same amout of elses as if's. i didnt know
that was illegal. was i wrong?

The sort of thing you have above *should* compile as two separate
if-statements, the first one without an else-clause. But that's not
compilable code anyway. Post a short complete example program that
compiles cleanly *except* for the error message that you describe above.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
474,142
Messages
2,570,818
Members
47,362
Latest member
eitamoro

Latest Threads

Top