Again Visual C++ Toolkit compiling C++

Started by Xor Stance, January 30, 2005, 10:32:48 PM

Previous topic - Next topic

Xor Stance


#include <iostream.h>
#include <conio.h>
void main()
{
clrscr;
int a,b,c;
cout<<"ingrese un numero \n";
cin>>a;
cout<<"ingrese otro numero \n";
cin>>b;
c= a+b;
cout<<"El Resultado es "<<c;
getch();
}


I save it as .cpp Since we started school 2 weeks of class, the teacher has only gave us the code and some explanations.
Actually I don't have a compiler and this was the only one I love and like it. Since my friends got it too, I just wanted to know if I can compile that source at C++ too.

after setting the environments,
cl file.cpp
file.cpp
file.cpp(1) : fatal error C1083: Cannot open include file: 'iostream.h': No such file or directory



#include <iostream.h>
#include <conio.h>
void main()
{
char a,b,c;
clrscr;
gotoxy(40,1);
cout<<Camille Vidan \n";
cin>>a;
got

This was a program for next class be will work, and finish it. Using gotoxy to place the x,y coordinates; and print something.

tenkey

To use the compiler from the command line, you will either need to add options on the command line, or set environment variables for the default locations of various files (include files and library files). There should be a batch file VCVARS32.BAT that you can run to set them up each time you open a command line box.
A programming language is low level when its programs require attention to the irrelevant.
Alan Perlis, Epigram #8

GregL


Xor Stance

Yeah I had set the environments from vcvars32.bat I read the link from Greg and I need to add set path of the library, now I can't try it since I have to sleep thanks.

Jibz

The C++ standard include files switched away from the .h extension a long time ago, though some compiler vendors still include them for backwards compatibility. So the correct way to include iostream is:


#include <iostream>


This also means that the stream functions are in namespace std, so you need a using directive or std:: prefixes.

conio.h is non-portable, and I don't think clrscr and gotoxy have been in many implementations except for old DOS compilers. You will probably need the Win32API to perform these operations.

You might want to check out one of the nice C++ sites :U.

Xor Stance

#5
The problem is that in my school they teach this type of C++ . But because I study for my own I will check it out. I had a doubt, what should I do with this path, or it's save as a text?


Set PATH=C:\Program Files\Microsoft Visual C++ Toolkit 2003\bin;%PATH%
Set INCLUDE=C:\Program Files\Microsoft Visual C++ Toolkit 2003\include;%INCLUDE%
Set LIB=C:\Program Files\Microsoft Visual C++ Toolkit 2003\lib;%LIB%


I could compile my C++ source code, but at the link which Greg gaves, it appears that the compiler needs it.

GregL

#6
Xor Stance,

Set the system environment variables permanently if you don't want to have to run the VCVARS32 batch file every time you want to use the compiler. The batch file stays in effect until you re-boot the PC or you logout. If you don't mind running the batch file every time, that's fine. Although, it seems that you need to learn more about setting environment variables in Windows.

Here is a link (for WindowsXP):

http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/environment_variables.mspx


Vortex

This one works:

#include <iostream>
#include <conio.h>
using namespace std;

void main()
{
int a,b,c;
cout<<"Enter a number \n";
cin>>a;
cout<<"Enter another number \n";
cin>>b;
c= a+b;
cout<<"The result is "<<c;
getch();
}



Compiling the source code:

cl /EHsc Sum.cpp