Syntax incorrect

Apr 21, 2009 at 6:37pm
While learning the basics of C++, I wrote the code below and when I used the command in "Visual Studio 2008 Command Prompt" like so ---

C:\.......>cl -EHsc If.cpp (The code file is named "If")

Then it gave me the new If.exe and If.obj. OK fine there right?

Then when I run the If.exe it says "The syntax of the command is incorrect".
So, just to double check I copy and paste the code from the if.cpp into Microsoft Visual C++ 2008 express edition under a new project and a new item in the resource files and compile it. OK again...

Then I go find this new .exe and run it and it works...

Same exact code... what is the problem?

---code below---
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
using namespace std;

int main()
{
int a, b, c;
a = 2;
b = 3;
if(a < b) cout << "a is less than b\n";
if(a == b) cout << "you won't see this\n";
cout << "\n";
c = a - b;
cout << "c contains -1\n";
if(c >= 0) cout << "c is non-negative\n";
if(c < 0) cout << "c is negative\n";
cout << "\n";
c = b - a;
cout << "c contains 1\n";
if(c >= 0) cout << "c is non-negative\n";
if(c < 0) cout << "c is negative\n";
system ("pause");
return 0;
}


*note the system ("pause") is just there to stop the prompt from closing ...I know there are other codes to do this but was just testing.
Apr 21, 2009 at 6:50pm
If you named the executable "if.exe" then consider that "if" has special meaning
to the command interpreter.
Apr 21, 2009 at 6:53pm
it seems that that fixed it by just changing the name... but I wonder why that happened

Thank You
Apr 22, 2009 at 12:15am
IF is a keyword to the Windows/DOS command interpreter used to parse batch files.

Topic archived. No new replies allowed.