Visual C++ farking with me

B

BigDAlcala

Ok. First I create a new text file. Then I input the following:

Code:
// BranchDemo - input two numbers. Go down one path of the program if the first argument is

//       greater than the second or the other path if not

#include <stdio.h>

#include <iostream.h>

int main(int nArg, char* pszArgs[])

{

  // input the first argument...

	int nArg1;

	cout << "Enter arg1: ";

	cin > nArg1;

	// ...and the second

	int nArg2;

	cout << "Enter arg2: ";

	cin > nArg2;

	// now decide what to do:

	if (nArg1 > nArg2)

	{

   cout << "argument 1 is greater than argument 2\n";

  }

	else

	{

  cout << "argument 1 is not greater than argument 2\n";

	}

	return 0;

}
Then I hit build. It asks to start a new workspace and I click yes. Then goes to the save as txt window. I name the txt file, and then in a split second it says 0 errors and 0 warnings. When I go to execute, it says the exe file doesn't exist and asks if I want to build it. I click yes, and then it says "Cannot execute program."

What gives? Please help me! thx!
 

antime

Extra Hard Mid Boss
VC++ depends on the file extension for its default action, so save the file with the extension "cpp" and it'll work. (If you use the extension "c" it will try to compile the file as a pure C program which won't work for this program.)

You probably noticed that Ikonboard isn't the best environment for C/C++ code as it will filter out your <included files> because they look like HTML tags. To get around this, enclose your program in [CODE] tags.
 
B

BigDAlcala

Cool, thx. One thing: It only lets me save as a text file. So, do I just type in filename.cpp or will it end up like filename.cpp.txt?
 

antime

Extra Hard Mid Boss
Just type in the full file name. You can also to through File/New... which will offer you a host of file types.
 
B

BigDAlcala

Ok, well, I tried it again, and now I get this:

Code:
--------------------Configuration: Branch Demo - Win32 Debug--------------------

Compiling...

Branch Demo.cpp

C:\Program Files\Microsoft Visual Studio\MyProjects\Branch Demo\Branch Demo.cpp(12) : error C2676: binary '>' : 'class istream_withassign' does not define this operator or a conversion to a type acceptable to the predefined operator

C:\Program Files\Microsoft Visual Studio\MyProjects\Branch Demo\Branch Demo.cpp(17) : error C2676: binary '>' : 'class istream_withassign' does not define this operator or a conversion to a type acceptable to the predefined operator

Error executing cl.exe.

Branch Demo.exe - 2 error(s), 0 warning(s)
Any idea....?
 

antime

Extra Hard Mid Boss
Ah, I thought that was just Ikonboard corrupting your quote. The stream operators are << and >>, so just change your code to
Code:
cin >> nArg1;
and it'll work just fine (I actually tested things for once).
 
B

BigDAlcala

Wooohooo!! Thank you!!!! I got that code from a C++ book and the cin only had one
Code:
<
. Wierd.
 
Top